d8 dex 编译因脱糖而失败

d8 dex compilation fails with desugaring

我无法让 d8 dex 编译器编译我的 jar 包:

$ 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

我试图阅读有关脱糖问题的内容,但无法深入了解 - 这个 jar 有什么问题?

如果您将 android.jar 或 java 运行时 jar 作为 --lib 传递给您的编译,您将不会看到该异常。 但是,在您的 d8 编译中还有很多其他警告,因为不存在脱糖所需的类型。这些来自您输入或类路径中没有的 mockito 包的依赖项。 也可以看看: https://developer.android.com/studio/command-line/d8#j8