admin管理员组

文章数量:1313121

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

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:

  • https://developer.android/studio/write/java8-support-table
  • https://developer.android/studio/write/java11-default-support-table

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:

  • https://developer.android/build/kotlin-support
  • https://github/dotnet/android/blob/main/Documentation/guides/D8andR8.md
Share Improve this question asked Jan 30 at 17:50 Bartek PaciaBartek Pacia 1,7263 gold badges21 silver badges48 bronze badges 3
  • 1 The Java version moves VERY slowly. It was slowed down even more by the decade long Oracle-Google lawsuit, and still might be affected by that. I would go under the assumption that it will never be updated. It's only been bumped about 3 times in the 13 or so years of Android, and has always been most of a decade behind Java versions. Also, Google is heavily moving towards Kotlin, so I wouldn't say its impossible for them to eventually leave it entirely if they find another runtime. – Gabe Sechan Commented Jan 30 at 18:41
  • @GabeSechan it's not about Java APIs available on the device, it's about the supported Java source compatibility for the compilation. – G00fY Commented Jan 31 at 10:12
  • @G00fY That changes nothing in my comment. THose newer features tend not to actually exist, for a variety of reasons (many of them dating back to that lawsuit). We were on 8 when it was over a decade out of date. Seeing advances in it are rare, and not a priority for Google – Gabe Sechan Commented Jan 31 at 16:09
Add a comment  | 

1 Answer 1

Reset to default 1

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.

本文标签: androidWhere is specified the highest Java language version that the d8 compiler acceptsStack Overflow