Skip to content

Desugar from a new project doesn't work at all (Java 8 > Java 7 Bytecode) #1738

Closed

Description

@duchnoun

Steps to Reproduce

  1. Create a new project (shared or pcl)
  2. Add in the csproj file sections : < AndroidEnableDesugar >True< /AndroidEnableDesugar >
  3. 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é ==========

test01 - Copie.zip

-->

Activity

  1. added
    bugComponent does not function as intended.
    Area: App+Library BuildIssues when building Library projects or Application projects.
    on May 29, 2018
  2. JonDouglas commented on May 29, 2018

    @JonDouglas
    Contributor

    I can confirm this behavior. @duchnoun I'm curious as to why you are adding desugar support 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 minSdkVersion needs 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 minSdkVersion to 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 the minSdkVersion rather than the "Already added" from the Xamarin.Android.Common.targets. I've thus marked this as a bug given the current experience.

  3. duchnoun commented on May 29, 2018

    @duchnoun
    Author

    @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)

  4. JonDouglas commented on May 29, 2018

    @JonDouglas
    Contributor

    @duchnoun Do you perhaps have a binding project with the WebRTC .aar included that has desugar enabled so we can look into that further? A file->New project shouldn't require desugar which is why I was asking you in the first place.

  5. duchnoun commented on May 30, 2018

    @duchnoun
    Author

    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

  6. Raj123456788 commented on May 31, 2018

    @Raj123456788

    Please update the work around. I am having same error as @duchnoun

  7. atsushieno commented on Jun 1, 2018

    @atsushieno
    Contributor
  8. atsushieno commented on Jun 1, 2018

    @atsushieno
    Contributor

    oops, sorry, wrong issue, and this explicitly says true.

  9. Raj123456788 commented on Jun 1, 2018

    @Raj123456788

    @atsushieno: It crashes my application if I desugar is true!

  10. atsushieno commented on Jun 1, 2018

    @atsushieno
    Contributor

    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.

  11. duchnoun commented on Jun 3, 2018

    @duchnoun
    Author

    @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

  12. atsushieno commented on Jun 8, 2018

    @atsushieno
    Contributor

    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.)

  13. yonkahlon commented on Jul 19, 2018

    @yonkahlon

    Any updates on this?

    @duchnoun did you work around this using the Google Groups discussion?

  14. jonathanpeppers commented on Jul 20, 2018

    @jonathanpeppers
    Member

    So to comment on the original problem:

    • File | New Xamarin.Android Project | Target Android 4.4 KitKit (API 19)
    • Add <AndroidEnableDesugar>True</AndroidEnableDesugar>
    • Get a build error

    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.

    It crashes my application if I desugar is true!

    @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.

  15. wiwski commented on Oct 17, 2018

    @wiwski

    Same here, I get a NoClassDefFoundError when building with Desugar enabled.

  16. jpobst commented on Mar 1, 2022

    @jpobst
    Contributor

    We have a newer version of D8 now, and we're kinda past the time when desugar was useful since it's now JDK11, so I think this is probably fixed/obsolete.

  17. ghost locked as resolved and limited conversation to collaborators on Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.bugComponent does not function as intended.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions