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?
Although the reason could be any depends on project I want to share the way I have fixed such error:
- rename failing jar to zip
- 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
- 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);