Start kotlin activity *.kt from java activity *.java?

In my case, I forgot to add

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

and

apply plugin: 'kotlin-android'
...
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

to build.gradle

Example

project build.gradle

...
buildscript {
  ext.kotlin_version = '1.1.51'
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    ...
  }
}

allprojects {
  repositories {
    jcenter()
    google()
  }
}

app build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
...

dependencies {
  ...
  compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

There is no real difference between classes produced by Java and Kotlin. If your code is statically resolved by Android Studio (as it should), then it must run unless Gradle is misconfigured.


You just do it like "normally" in Java:

Intent intent = new Intent(getActivity(), KotlinActivity.class);
startActivity(intent);

Just don't forget to add Kotlin to your project fist (in the gradle files). Otherwise it won't work.


File -> Invalidate Caches/ restart...