Hi everyone, I am wondering if there is any docume...
# android
a
Hi everyone, I am wondering if there is any document explaining what Java 8 APIs can R8 desugar without additional project configuration, like setting
coreLibraryDesugaring
dependency to
com.android.tools:desugar_jdk_libs:1.1.8
described here: https://developer.android.com/studio/write/java8-support-table
k
AFAIK, you need the desugaring libraries in your project because desugaring calls methods/classes in those libraries...
r
As explained here, some language features (such as lambdas) are desugared by D8 without the desugar libarary but all new APIs require desugaring library
Also note that if the JVM target for kotlin is 8+ it will generate code using Java 8 APIs so you’ll need desugaring for that (unless your minsdk is 26+)
And if your kotlin version is 1.8+ you’re required to use JVM version 8 because lower versions aren’t supported
a
Thanks @kenkyee @Robert Williams To add some context: I am implementing a tool for verifying whether a library is compatible with JDK 1.6 to make sure applications using the library can run on older Android devices. The tool runs regularly on CI to catch changes that break compatibility. It is my understanding that some Java 1.8 API can be desugared by R8, and their usages won’t crash on older Androids. I want to add those API to the list of methods the tool should ignore. However, I wasn’t able to find a public source with the information. I found the following related issue: https://issuetracker.google.com/issues/114711928 Also this table: https://developer.android.com/studio/write/java8-support-table, which requires additional project configuration. Libraries can’t rely on it. Thus was wondering where I could find the list of Java 1.8 API that can be safely used in a library compiled with jvmTarget/sourceCompatibility/targetCompatibility = 1.8.
k
Maybe rummage the desugaring source code? https://android.googlesource.com/platform/external/desugar/+/refs/heads/main/java/com/google/devtools/build/android/desugar I've never seen a public doc either besides the small blurb Robert mentioned from a long time ago when desugaring was added. I'd suggest flagging everything...things can always change in the future and Android devs always use the desugaring libraries AFAIK... relying on it just to handle lambdas would leave you open to foot gunning...
a
Unfortunately, flagging everything is not feasible. Because libraries can use, e.g., data classes:
Copy code
data class MyClass(val value: Int)
Kotlin compiler generates a
hashCode
implementation for the data class that uses the static
Integer.hashCode(int)
added in Java 1.8.
👍 1
The static
Integer.hashCode(int)
is desugared by R8 by the way