As an androiddev... whats the tldr on what I shoul...
# random
c
As an androiddev... whats the tldr on what I should be using as jdk declaration in the project? i.e. should i basically be setting everything to 17, or is 21 the new "standard" yet? or can i just omit these so that i dont need to add 17 in a bunch of places?
Copy code
android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
}
j
tldr 21
25 is LTS now, so you could use that if you're on Gradle 9.1
c
nice. and should i set those above flags to 21 or are there any more? idk what even happens if i dont set them lol. default to 8 i suppsose?
j
They default to something, not sure what
I usually just set
jvmToolchain
and call it a day. If you're not using that, then you only have those 3 to set
e
I still have mine set to 17 I believe. Last time that I tried updating it to 21 AGP had some issues (don't remember what exactly)
1
c
aha. so i can call jvmToolchain instead of calling those 3? i will do that instead then. i just got put on a new project at work and saw the build file contains
Copy code
compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
and
Copy code
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {jvmTarget.set(JvmTarget.JVM_11)}
}
and that just looks smelly hence the question. let me look into jvmToolchain
j
jvmToolchain has some extra implications, it'll force you to use a Java version that matches whatever you specify, rather than allowing upgrades that will still compile to some version
I find it to be fine for smaller projects, or when consistency is key
c
thanks. wish android docs just had a "use this approach and this version" lol \
e
there's no reason to use newer targets on android - it'll be desugared and dexed anyway
👀 1
1
and toolchains additionally bring along jdkHome which doesn't work for Android since they need to use their own regardless
c
gotcha. which toolchain would you say is the "standard" to target now ephemient? 17?
j
there's no reason to use newer targets on android
Not true. You definitely don't get newer language features until Android as a platform adds them, but you do benefit from compile-time performance improvements
Well, for JDK updates you benefit from those kappa
e
you get those improvements regardless of target
c
this seems "wrong", thorugh right?
Copy code
tasks.withType<KotlinCompile>().configureEach {
  compilerOptions { jvmTarget.set(JvmTarget.JVM_[insert version]) }
}
seems like i should just do
Copy code
android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_[insert version]
        targetCompatibility = JavaVersion.VERSION_[[insert version]
    }
    kotlinOptions {
        jvmTarget = "[insert version]"
    }
}
💯 1