Update (2)
If you are using
Android Studio Arctic Fox version 2020.3.1 Beta 2
and
Gradle Plugin version 7.0.0-beta02
you are good to go and can just put put your code in src/main/kotlin
.
Android Studio shows it as kotlin
in the file tree. No need for adding the directory to the sourceSet
as shown below.
Update (1)
Kotlin is finally coming to AndroidSourceSet. If you use the latest Android Gradle Plugin
version 7.0 alpha
, you can use:
android.sourceSets.all {
kotlin.srcDir("src/$name/kotlin")
}
This works fine in Android Studio 3.6.2
and should be the most versatile solution until AndroidSourceSet
starts supporting Kotlin directly. Just add the following snippet at the end of your app/build.gradle[.kts]
:
android.sourceSets.all {
java.srcDir("src/$name/kotlin")
}