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
- 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
1 Answer
Reset to default 1I 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.
版权声明:本文标题:android - Where is specified the highest Java language version that the d8 compiler accepts? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741946445a2406443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论