I cannot find the authoritateive answer anywhere.
I know that what d8 is and that it performs desugaring. Basically, up to what Java language version can it desugar?
I found these websites that list which APIs can be desugared:
but it's APIs, not syntax features of the language itself.
I wonder if using
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
is valid since which AGP version? And when will I be able to put JavaVersion.VERSION_21
?
In other words I'm looking for a table like this from an authoritative source:
AGP version | d8 version | Java source handled / list of JEPs supported |
---|---|---|
8.7 | ?? | var, switch expressions |
------------- | ------------ | ----------------------- |
8.8 | ?? | records |
Pages I found so far that don't answer my question:
I would suggest you create a ticket in the issue tracker about this missing documentation. I would also expect the information you are looking for inside the compatibility-faq.md.
About your question: You can see in the sources, that the D8/R8 team already added support for e.g. new pattern matching for switch introduced with Java 21 back in May 2024. This should have been released with AGP 8.6.
So in general it should be safe to set sourceCompatibility
to VERSION_21
if you only use language features and not rely on desugaring of new library APIs (like Virtual Thread). But I am not sure if there are might be any language features R8/D8 is currently not supporting.