I'm bumping up version in one of my Android projec...
# android
d
I'm bumping up version in one of my Android project. I see here https://developer.android.com/studio/preview/features#jdk-17 that I'm supposed to use JDK 17 now. But I'm confused 1. Do I set the kotlin toolchain to 17? 2. Am I supposed to also set the jvmTarget to 17? 3. Do I still need the
android.compileOptions
? 4. Does it mean I don't need desugaring anymore for java.time and the likes? I think I missed something, can anyone shed some light on this topic? Which is the recommended setup regarding the kotlin / java toolchain on an Android Project using the last AGP 8.1.0-alpha06 and Android Studio Giraffe | 2022.3.1 Canary 6? Thank you
😶 1
@kenkyee asking about your not kotlin reaction: isn't this the #android channel?
and this is asking about jvmTarget version which kinda is kotlin related
I think I fall in the description "Using Kotlin to build Android apps". I wanna know if the kotlin compiler with jvm target 17 is going to produce Jar / Dex compatible with the devices
I don't think there are many things specific to android in "Using Kotlin to build Android apps" other than the build chain and maybe some library
k
Click on the info section up top. The kotlin compiler works fine with jdk17
d
I'm sorry, which info section? I only see 2 pinned messages Which say:
General kotlin behaviours that should work in anywhere but don't work (to be asked in #android )
Dex is one of the target for android and I'm asking if I can use jdk 17 and target jdk 17 for Android without issues on devices
k
yes and yes for 17..folks have done it
you're asking about whether jdk17 works
d
I'm asking if I can encounter runtime crashes on missing methods on some older device. Years ago I recall that targeting JDK greater than 1.8 kotlin used some feature of jdk that wasn't available on devices. One such example, if I recall, was
getOrElse
for Map. It would compile but than crash at runtime on devices where the jdk didn't have the method. This is just an example. I just want to know if this could happen setting target jdk 17.
k
that was totally different...you needed to enable desugaring. But several companies are using JDK17 already including Slack and Google.
d
This was before desugaring was a thing. And I enable desugaring only if I need it (ex. Using java.time). So what I'm asking here is: will the build targeting android do the right thing or do I have to enable desugaring everywhere? Cause apparently now we are forced to use jdk 17. If desugaring is mandatory why not including it directly in the build?
k
desugaring is only needed if you use Java17 code...if you only use Kotlin, it won't matter
d
So you are saying I'll have to remember which functions are not available in java 8 and avoid using them or enable desugaring. Example:
String.isBlank()
is new to java 11. It wasn't there in Java 1.8. As far as I understand it targeting java 11 or 17 tells the compiler that method is available. But at runtime, in Android, it will not be if there: https://source.android.com/docs/setup/start/older-versions#jdk Are you saying that kotlin will not map to any method after java 8 when building for Android and will know what to do? There's not much documentation about this nor on the Kotlin side nor on android side.
k
Kotlin compiler only targets JVM 8 and JVM11 bytecode. It doesn't really know about the Java language
you could also just test it...
d
Yes, bytecode, sure, but I'm not talking about bytecode, I'm talking about JDK and methods that are available on that JDK level. I sure can test it out. But I'd feel more confident to have some official statement on this.
Anyway, do you still think this is not kotlin? Cause that confused me, I don't want to be off topic, but at the same time I don't get how this is :-)
k
This channel is for helping the Jetbrains folks...for issues that Kotlin may have on Android. It's not a channel for general Android dev questions.
d
I see, than I'm definitely off topic. Do you know if there's a channel where my question would be in-topic in this server?
k
this entire slack server is for jetbrains
only the compose channel is a jetbrains/google combo for Jetpack Compose
d
Eh, it's the only server I know where sometimes you get answers from googlers :-) Thanks anyway! I'll look into it myself
k
that's because they take time out of their day and help folks sometimes...it's NOT an official channel
d
I know. I do the same thing over in the discord server you linked in the description of this channel. But there are questions that only them can answer.
140 Views