I am trying to use Kotlin V1.2.70, Gradle V4.10.1 and Java 11. When compiling the project using gradle, an error saying "Unknown JVM Target Version: 11. Supported versions: 1.6, 1.8".
Does the Kotlin compiler supports Java 11 (produces code compatible with Java 11 JVM)? If so, how to configure that with gradle?
Yes. Kotlin is supported as a first-class language on Android.
hadrianectorsm: Do you know if kotlin is already supported by java 14 ? Yes, it is. You can use 13 on compiler without any issue.
Kotlin 1.6. 0 supports JDK versions from JDK 1.6 through 17 (the latest released version at the moment).
The JDK 16 release includes plans to stabilize a new Java class type called record. To provide all the benefits of Kotlin and maintain its interoperability with Java, Kotlin is introducing experimental record class support.
The Kotlin compiler supports the JVM 9, 10, 11, and 12 bytecode versions as target since Kotlin 1.3.30 (changelog).
Prior to 1.3.30, only JVM 1.6 and 1.8 bytecode versions were supported as targets. Since you used 1.2.70, specifying JVM 11 bytecode as target led to the error you mentioned.
There are two solutions:
Specify 1.8 as JVM target bytecode version. As @yole said in his answer, this is fully compatible with JVM 11. In fact, as mentioned in the changelog of Kotlin 1.3.30, newer JVM target bytecode versions currently don't add any bytecode optimizations beyond the ones supported in 1.8, so it really doesn't make any difference for now anyway.
Upgrade to Kotlin 1.3.30 (or newer), then you can keep 11 as the JVM bytecode target value. The advantage is that you will automatically benefit from additional bytecode optimizations in future versions of the Kotlin compiler.
The bytecode generated by the Kotlin compiler, when the target version is set to either 1.6 or 1.8, is fully compatible with JVM 11.
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