Repository navigation
Desugar from a new project doesn't work at all (Java 8 > Java 7 Bytecode) #1738
Description
Steps to Reproduce
- Create a new project (shared or pcl)
- Add in the csproj file sections : < AndroidEnableDesugar >True< /AndroidEnableDesugar >
- Generate solution
Expected Behavior
Compile should work
Actual Behavior
Dx fail with Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
Version Information
Build Tools v 27.0.3
Sdk tools 26.1.1
Platform : All
Log File
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension$AbstractDesugaringStrategy;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension$ConcurrentWeakIdentityHashMap;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension$ConcurrentWeakIdentityHashMap$WeakKey;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension$MimicDesugaringStrategy;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension$NullDesugaringStrategy;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension$ReuseDesugaringStrategy;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
1> Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension$AbstractDesugaringStrategy;
1>
1> UNEXPECTED TOP-LEVEL EXCEPTION:
1> java.lang.RuntimeException: Translation has been interrupted
1> at com.android.dx.command.dexer.Main.processAllFiles(Main.java:615)
1> at com.android.dx.command.dexer.Main.runMonoDex(Main.java:313)
1> at com.android.dx.command.dexer.Main.runDx(Main.java:291)
1> at com.android.dx.command.dexer.Main.main(Main.java:247)
1> at com.android.dx.command.Main.main(Main.java:94)
1> Caused by: java.lang.InterruptedException: Too many errors
1> at com.android.dx.command.dexer.Main.processAllFiles(Main.java:607)
1> ... 4 more
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2254,3): error : java.lang.IllegalArgumentException: already added : Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
1> DexOutputs:
1>Exécution de la tâche "CompileToDalvik" terminée -- ÉCHEC.
1>Génération de la cible "_CompileToDalvikWithDx" terminée dans le projet "test01.Android.csproj" -- ÉCHEC.
1>
1>ÉCHEC de la build.
1>
1>"c:\mimichat\test01\test01\test01.Android\test01.Android.csproj" (cible par défaut) (1) ->
1>(_CompileToDalvikWithDx cible) ->
1> C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2254,3): error : java.lang.IllegalArgumentException: already added : Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
1>
1> 0 Avertissement(s)
1> 1 Erreur(s)
1>
1>Temps écoulé 00:00:31.21
========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========
-->
Activity
JonDouglas commentedon May 29, 2018
I can confirm this behavior. @duchnoun I'm curious as to why you are adding
desugarsupport to a new project? Desugar is mostly needed in binding librarys that make use of Java 8 Language features.Secondly, to ensure proper desugar support for certain APIs, your
minSdkVersionneeds to be set appropriately. See https://developer.android.com/studio/write/java8-support#supported_features for more details.For example, if I took your sample and increased the
minSdkVersionto API 24, the project will build successfully. We should definitely improve this and throw an error message in this area giving a note about increasing theminSdkVersionrather than the "Already added" from theXamarin.Android.Common.targets. I've thus marked this as abuggiven the current experience.duchnoun commentedon May 29, 2018
@JonDouglas , i add desugar on new project only because i've try to identify my problem. The main project is a try to use the AAR library WebRTC , but since november 2017 they have down the java 7 support (before they was Desugar it) ; and now they use java 8 and lambda and other feature from java 8. They tell that now the developper need to desugar the code itself. That's why i would use Desugar ...
Before when they desugar themself , the Api work on API 19 ...
The goal of project is to made a xamarin webrtc plugin with a maximum compatibility
(Sorry , my english is bad .. i'm french)
JonDouglas commentedon May 29, 2018
@duchnoun Do you perhaps have a binding project with the WebRTC
.aarincluded that hasdesugarenabled so we can look into that further? A file->New project shouldn't requiredesugarwhich is why I was asking you in the first place.duchnoun commentedon May 30, 2018
Sure, Sorry the size of the archive , the AAR is big.
This project should require desugar operation. It was working before was older api from webrtc because they desugar before ...
The AAR was create by me from sources of webrtc in this month. (But same with precompiled library from webrtc website ..)
Sure i could use an old version, but i want to do a maintain project with recent version of webrtc ..
Some discussion about it here : https://groups.google.com/forum/#!topic/discuss-webrtc/V1h2uQMDCkA
MimichatV2.zip
Raj123456788 commentedon May 31, 2018
Please update the work around. I am having same error as @duchnoun
atsushieno commentedon Jun 1, 2018
Have you tried adding `true' in your app project?
https://github.com/xamarin/xamarin-android/blob/master/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L278
atsushieno commentedon Jun 1, 2018
oops, sorry, wrong issue, and this explicitly says true.
Raj123456788 commentedon Jun 1, 2018
@atsushieno: It crashes my application if I desugar is true!
atsushieno commentedon Jun 1, 2018
The desugar situation is complicated. Android Gradle Plugin (used in Android Studio) once incorporated desugar_deploy.jar to deal with desugaring. Now Google introduced d8 and quickly abandoned standalone desugar tool. Since Google has already removed desugar_deploy from Android Gradle Plugin setup, we will have to do the same.
Right now d8 is offered as an independent package on NuGet (xamarin-android-d8-build) but d8 will be also part of our standard build implementation along with r8 (Xamarin.Android.Build.Tasks) at #1489 (which is suffered from another blocker that the build logs are not investigatable). Things will be resolved accordingly.
duchnoun commentedon Jun 3, 2018
@atsushieno , yes i've see that Android studio use d8; and i've see your nugget package , but it doesn't help; D8 with project xamarin seem to don't work. Have you an idea when this will work ? (this year ? on few month ? few day ? )
Thanks
atsushieno commentedon Jun 8, 2018
I just recorded an issue to explain current situation regarding this issue. (I feel sorry for inconvenience, it's a problem in maintaining / managing product development which is irrelevant to any of you.)
yonkahlon commentedon Jul 19, 2018
Any updates on this?
@duchnoun did you work around this using the Google Groups discussion?
jonathanpeppers commentedon Jul 20, 2018
So to comment on the original problem:
<AndroidEnableDesugar>True</AndroidEnableDesugar>It appears the cause here is using the 27.x support libraries along with desugar targeting API level 19.
I can confirm that building an app without the support libraries works with API level 19. Such as our sample here. However, that isn't too helpful, since all apps need the support library!
The real fix here is to get D8 support, but we don't have a timeline for when it will be done, unfortunately.
However, I can say it is definitely a priority for us--since D8 also has the promise of faster build times.
I'll try to follow up when I have more info.
@Raj123456788 if you are still getting a crash when enabling desugar, we have a fix in
master, but you might try the workaround I mention here for now.wiwski commentedon Oct 17, 2018
Same here, I get a NoClassDefFoundError when building with Desugar enabled.
jpobst commentedon Mar 1, 2022
We have a newer version of D8 now, and we're kinda past the time when
desugarwas useful since it's now JDK11, so I think this is probably fixed/obsolete.