Search code examples
runtimeexceptiondexandroid-d8jdk-desugaring

d8 dex compilation fails with desugaring


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?


Solution

  • 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