This lets Android Studio know that the kotlin directory is a source root, so when the project model is loaded into the IDE it will be properly recognized. Alternatively, you can put Kotlin classes in the Java source directory, typically located in src/main/java.
使用 Gradle Kotlin DSL
構(gòu)建腳本后,將源代碼根目錄java
修改為kotlin
。
Kotlin 版本 build.gradle.kts
:
android {
...
sourceSets["main"].java.srcDir("src/main/kotlin")
}
對應(yīng)的 Groovy 版本 build.gradle
:
android {
...
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}