I have an Android App developed using Java. I now want to start using Kotlin for the same app. Is it possible to use Kotlin and Java side-by-side in an existing app?
In Android Studio 4, there is no need to manually configure Kotlin for a Java project.
When adding Kotlin files to a Java project, Android Studio will automatically setup Kotlin.
Here is the full procedure:
Activity
for example)Kotlin
as the languageNote: When it finished, it could not resolve the R file in the Kotlin Activity. To fix this, I just hit hovered over the red R
in the editor and hit alt-enter
.
Finally, in my MainActivity.java:
Intent launchNewIntent = new Intent(this, KotlinActivity.class);
startActivityForResult(launchNewIntent, 0);
This code opens the KotlinActivity from the MainActivity in Java.