Android Studio built-in JRE is 11 version. And Artic Fox allows to use Java 11 for compiling projects:
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
But we also have Kotlin options
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
What JVM target version should we set now?
jvmTarget = JavaVersion.VERSION_1_8
or jvmTarget = JavaVersion.VERSION_11
Kotlin library uses JDK 8:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
kotlin-stdlib-jdk11
doesn't exist yet
All next configurations works with Artic Fox:
#1
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}
#2
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
#3
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
But what should we choose?
Yes. Kotlin is supported as a first-class language on Android.
A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects.
Android Studio 2021.1 “Bumblebee” has a new Device Manager and improved Apple Silicon support. Android Studio is the main integrated development environment (IDE) for creating Android applications, with a feature-packed code editor, debugging tools, emulators, and much more.
Android Studio Chipmunk | 2021. With Android Studio Chipmunk Patch 2 and Android Gradle 7.2. 2, you can compile against Android 13 APIs by setting compileSdk=33 . The highest supported minimum SDK version is 32.
If you're using Android Studio Artic Fox 2020.3.1, the first choice is the preferred option.
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}
Now coming to the kotlin-stdlib, you can use the jdk8 version.
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
The kotlin-stdlib-jdk8 library is fully compatible with the JDK 11 SDK.
Alternatively, for Kotlin only projects you can also ignore the kotlin-stdlib-jdk8 dependency as the Gradle plugin will automatically add the necessary library sources during compilation.
According to current documentation use java 8:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
Android Developer docs (Java8 Support) is silent wrt. regarding jvmTarget and Java 11.
Kotlin Docs says that 1.8 is the default jvmTarget as of Kotlin 1.5.
Also note that when creating a new Kotlin-based project in the current Android Studio Artic Fox 2021.3.1 Patch 3, it creates a build.gradle with jvmTarget 1.8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With