D8 desugaring: Unexpected type adjustment

允我心安 提交于 2019-12-24 06:23:23

问题


I enable the new D8 desuaring in Android Studio 3.1.3 in my gradle.properties:

android.enableD8.desugaring=true

Now the compilation fails with this error in one of the java-only modules:

com.android.tools.r8.errors.Unreachable: 
Unexpected type adjustment from java.lang.String[] to java.lang.Object[]

Here is the full stack-trace
Note: the old dexer works fine (when I deactivate the option above)

I've checked the java-module and I cannot even find String[] or Object[] in any of the java-files. Adding --debug --scan also didn't give me any more insights in what the problem could be.

Any ideas what the problem can be or how I can get more detailed error info from the dexer: e.g. in which file the erroneous code is?


回答1:


Although the reason could be any depends on project I want to share the way I have fixed such error:

  1. rename failing jar to zip
  2. run D8 directly on it, something like D:\Development\Tools\android-sdk\build-tools\28.0.2\d8.bat D:\Development\<PROJECT_PATH>\build\intermediates\intermediate-jars\debug\classes.jar.zip
  3. remove classes one by one from zip and go back step 2 until exception is gone

To speed up the process I was removing files in bulk to narrow down to the package and then to the exact file causing D8 failure.

As it turned out it was the following code (I'm using com.annimon.stream.Stream):

Stream.of(SOME_MAP).map(Map.Entry::getValue).findFirst().orElse(null);

where SOME_MAP is HashMap<String, String[]> and workaround was to use

Stream.of(SOME_MAP).map(entry -> entry.getValue()).findFirst().orElse(null);



来源:https://stackoverflow.com/questions/50999313/d8-desugaring-unexpected-type-adjustment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!