d8 dex compilation fails with desugaring

482 views Asked by At

I can't get d8 dex compiler to compile my jar package:

$ wget https://repo1.maven.org/maven2/org/mockito/mockito-core/3.6.0/mockito-core-3.6.0.jar
$ java -jar d8_2.1.86.jar --output /tmp mockito-core-3.6.0.jar 2>&1 >/dev/null | grep "Compilation"
com.android.tools.r8.errors.CompilationError: Class or interface java.lang.RuntimeException required for desugaring of try-with-resources is not found.
Compilation failed

I tried to read about desugaring problems but couldn't get very far - what's wrong with this jar?

1

There are 1 answers

4
Rico Wind On BEST ANSWER

If you pass android.jar or the java runtime jar as --lib to your compilation you will not see that exception. There is, however, a lot of other warnings in your d8 compilation, because types that are needed for desugaring are not present. These are from dependencies of the mockito package that you don't have in your input or on classpath. See also: https://developer.android.com/studio/command-line/d8#j8