Android - Desugar classes in @aar package

I am trying to create an @aar package from my library that will be used as a dependency inside client projects.

In my library module, I use:

compileOptions{
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

I want to smooth out the code and make it compatible with Java 7 before reaching client dependencies. This means that I need to actually provide the @aar package, where Lambda functions and all other Java 8 related functions are already ported to Java 7 bytecode.

The problem I am facing is that on the library module using:

apply plugin: 'com.android.library'

the desugaring task is not running, which means the bytecode contains Java 8 imports, for example:

java.lang.invoke.LambdaMetafactory

and this will cause my client to also update its JavaVersion.VERSION_1_8 compilation options, which I want to avoid.

, : desugaring, com.android.library, com.android.application? , , ?

+8
2

com.android.library , aar .class ( .dex). ( ) .

, , , , - Java 8, , ( javac, /, .aar. ):

enter image description here

UPDATE: - , "com.android.library" . Desugaring - .class, desugar, gradle.build, :

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_7
}
0

, Android "desugar" bazel desugar java8 ( D8). , . : 1. bazel 2. desugar.jar 3. desugar.jar (classes.jar aar) 4. desugared jar aar.

:

https://github.com/bazelbuild/bazel/tree/1f684e1b87cd8881a0a4b33e86ba66743e32d674/src/tools/android/java/com/google/devtools/build/android/desugar

https://github.com/bazelbuild/bazel/issues/2975

, com.android.application. .

, , desugar Aar , . , , ( app minsdk> = 24, ).

0

Source: https://habr.com/ru/post/1691747/


All Articles