https://kotlinlang.org logo
#android
Title
# android
l

Lilly

04/17/2020, 2:57 PM
Stupid question, but is it possible to compile against Java 12 (Java 11 is working):
Copy code
compileOptions {
        sourceCompatibility = JavaVersion.VERSION_12
        targetCompatibility = JavaVersion.VERSION_12
    }

    kotlinOptions {
        jvmTarget = "12"
    }
I get Unsupported class file version: 56. AS: 4.1 C5 Gradle: 6.3 Kotlin: 1.3.72 JDK: 14.0.1 When I'm searching for "android java 12/13 support" I find sources that claim gradle/kotlin/IntelliJ is supporting both so did I miss something or is it just not supported yet?
m

Matt Lang

04/17/2020, 3:06 PM
From my understanding, Android only supports up to Java 8 (partially) right now: https://developer.android.com/studio/write/java8-support
j

jw

04/17/2020, 3:14 PM
You can set kotlin to target as high as 11. D8 will reject 12+, for now (see https://issuetracker.google.com/issues/141587937). Setting the Java version higher than 8 changes how javac compiles which removes the bootclasspath argument that Android relies on to link against the android.jar from the Android SDK (see https://issuetracker.google.com/issues/139013660)
👍 1
l

Lilly

04/17/2020, 3:45 PM
That is exactly what I'm looking for, thanks boss. Nice overview btw @jw But why can I run my app with java source/target 11 properly. Shoudln't it fail?
j

jw

04/17/2020, 3:45 PM
are you on an old version of Gradle?
Only the newer versions will set the
-release
flag on javac when you set the version higher than 8, which is what breaks Android
l

Lilly

04/17/2020, 3:46 PM
I have the latest one, 6.3.
j

jw

04/17/2020, 3:47 PM
It shouldn't work. There's example projects in that repo which demonstrate it. Are you referencing Android APIs or is the project empty? It'll look like it works if you're not referencing Android APIs anywhere.
l

Lilly

04/17/2020, 3:50 PM
This is currently working for me:
Copy code
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
    jvmTarget = "11"
}
AS: 4.1 C5 Gradle: 6.3 Kotlin: 1.3.72 JDK: 14.0.1
The project contains the ``LoginTemplate`` classes from Android Studio --> New -> Activity -> Login Activity
I can upload the project if you want to have a look. It's just a sample project.
j

jw

04/17/2020, 4:15 PM
do you have any Java source files?
l

Lilly

04/17/2020, 5:09 PM
No, only kt and kts files
j

jw

04/17/2020, 5:21 PM
so you'll only have the BuildConfig generated which doesn't reference any Android APIs
that's why it still works
l

Lilly

04/17/2020, 8:06 PM
Ah ok, so is it right that I dont have to define java source/target because I have no java source files?
I mean when I have a project with only kotlin files, then the whole compilation process is done by kotlin compiler. So javac does not even come into play and in turn makes the definition of source/targetcompatibility obsolete or am I wrong?
j

jw

04/17/2020, 11:53 PM
it still compiles the BuildConfig, but otherwise is unused, yes
l

Lilly

04/18/2020, 4:06 PM
ok thanks!