0

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?

OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87

1 Answers1

1

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

Rico Wind
  • 261
  • 1
  • 2
  • it's not working when adding `--lib android-4.1.1.4.jar` ... :( – OrenIshShalom May 20 '21 at 11:12
  • 1
    Works for me: $ wget https://repo1.maven.org/maven2/org/mockito/mockito-core/3.6.0/mockito-core-3.6.0.jar $ wget https://storage.googleapis.com/r8-releases/raw/2.1.86/d8.jar $ java -jar d8.jar --lib ~/src/r8/third_party/android_jar/lib-v29/android.jar mockito-core-3.6.0.jar Still gives a lot of warnings about missing classes (expected), but does not fail compilation – Rico Wind May 21 '21 at 05:07
  • I get the android jar from here: https://repo1.maven.org/maven2/com/google/android/android/4.1.1.4/android-4.1.1.4.jar, I guess I should try another version? where can I find the version you used? thanks !! – OrenIshShalom May 21 '21 at 07:14
  • 1
    You can download the android.jar using sdkmanager: https://developer.android.com/studio/command-line/sdkmanager I validated just now with: ./sdkmanager --sdk_root=/tmp/sdk/cmdline-tools --install "platforms;android-30" – Rico Wind May 25 '21 at 05:45