Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Resolved Duplicate class found in modules (different versions of same library imported by different plugins)

Discussion in 'Android' started by JustSuds, Apr 17, 2022.

  1. JustSuds

    JustSuds

    Joined:
    Jul 25, 2013
    Posts:
    7
    I'm using Unity 2021.3.0f1 and trying to build my game for Android. This is an empty Unity project with the latest versions of the following plugins installed, in this order, by following their respective documentations:
    • ZXing Unity
    • SentryIO
    • Unity Mediation
    • Firebase (Analytics, Firestore, Cloud Functions, Authentication)
    I'm using Unity Cloud Build for CI/CD.

    The crux of the problem is that both Firebase and Sentry use the gson library, and this causes a conflict as below:

    Duplicate class com.google.gson.ExclusionStrategy found in modules com.google.code.gson.gson-2.8.9.jar (com.google.code.gson.gson-2.8.9.jar) and gson-2.8.5.jar (gson-2.8.5.jar)


    gson-2.8.9 is provided by Firebase and gson-2.8.5 is provided by Sentry.

    I have absolutely no idea how to resolve this. In my local copy, I was able to simply remove either version (I tested both) from my project and it then built and ran just fine. But the cloud build obviously runs some sort of plugin resolver and grabs a copy of both, leading to the conflict.

    Please help! Thank you

    the cloud build does use a slightly older version of unity, but i don't believe this is the problem because my local version experiences the same issue.

    The entire cloud build compact log is below:


    1: [Unity] Initialize engine version: 2021.2.17f1 (efb8f635e7b1)
    2: [Unity] Assets\Scripts\BarcodeScanner.cs(46,20): warning CS0414: The field 'BarcodeScanner._message' is assigned but its value is never used
    3: [Unity] warning: Using obsolete custom response file 'mcs.rsp'. Please use 'csc.rsp' instead.
    4: [Unity] Assets\Scripts\BarcodeScanner.cs(46,20): warning CS0414: The field 'BarcodeScanner._message' is assigned but its value is never used
    5: [Unity] UnityEngine.Debug:LogWarning (object)
    6: [Unity] Assets\Scripts\BarcodeScanner.cs(46,20): warning CS0414: The field 'BarcodeScanner._message' is assigned but its value is never used
    7: [Unity] warning: Using obsolete custom response file 'mcs.rsp'. Please use 'csc.rsp' instead.
    8: [Unity] warning: Using obsolete custom response file 'mcs.rsp'. Please use 'csc.rsp' instead.
    9: [Unity] Assets\Scripts\BarcodeScanner.cs(46,20): warning CS0414: The field 'BarcodeScanner._message' is assigned but its value is never used
    10: [Unity] UnityEngine.Debug:LogWarning (object)
    11: [Unity] ERROR: Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
    12: [Unity] WARNING: The option setting 'android.enableR8=true' is deprecated.
    13: [Unity] WARNING: The option setting 'android.enableR8=true' is deprecated.
    14: [Unity] ERROR:
    15: [Unity] java.lang.RuntimeException: Duplicate class com.google.gson.ExclusionStrategy found in modules com.google.code.gson.gson-2.8.9.jar (com.google.code.gson.gson-2.8.9.jar) and gson-2.8.5.jar (gson-2.8.5.jar)
    16: [Unity] java.lang.RuntimeException: Duplicate class com.google.gson.ExclusionStrategy found in modules com.google.code.gson.gson-2.8.9.jar (com.google.code.gson.gson-2.8.9.jar) and gson-2.8.5.jar (gson-2.8.5.jar)
    17: [Unity] java.lang.RuntimeException: Duplicate class com.google.gson.ExclusionStrategy found in modules com.google.code.gson.gson-2.8.9.jar (com.google.code.gson.gson-2.8.9.jar) and gson-2.8.5.jar (gson-2.8.5.jar)
    18: [Unity] WARNING: The option setting 'android.enableR8=true' is deprecated.
    19: [Unity] java.lang.RuntimeException: Duplicate class com.google.gson.ExclusionStrategy found in modules com.google.code.gson.gson-2.8.9.jar (com.google.code.gson.gson-2.8.9.jar) and gson-2.8.5.jar (gson-2.8.5.jar)
    20: [Unity] WARNING: The option setting 'android.enableR8=true' is deprecated.
    21: [Unity] at UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) [0x00033] in <6debbbecb74f4536994a9d13d4ceb758>:0
    22: [Unity] at UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) [0x0002d] in <6debbbecb74f4536994a9d13d4ceb758>:0
    23: [Unity] at UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) [0x0000a] in <6debbbecb74f4536994a9d13d4ceb758>:0
    24: [Unity] at UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) [0x0001f] in <6debbbecb74f4536994a9d13d4ceb758>:0
    25: [Unity] Rethrow as GradleInvokationException: Gradle build failed
    26: [Unity] Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
    27: [Unity] ERROR: Player export failed. Reason: CommandInvokationFailure: Gradle build failed.
    28: [Unity] java.lang.RuntimeException: Duplicate class com.google.gson.ExclusionStrategy found in modules com.google.code.gson.gson-2.8.9.jar (com.google.code.gson.gson-2.8.9.jar) and gson-2.8.5.jar (gson-2.8.5.jar)
    29: [Unity] WARNING: The option setting 'android.enableR8=true' is deprecated.
    30: [Unity] [Performance] InitializeOnLoad EntitlementsErrorChecker.OpenFirstEntitlementError : 2 samples, Peak. 45.9 ms (1.6x), Avg. 29.4 ms, Total. 58.75 ms (0.0%)
    31: ! build of 'bitbeasts-android-main-branch' failed. exit
    32: publishing finished successfully.
    33: Finished: FAILURE
     
    Last edited: Apr 17, 2022
  2. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,983
    Select one of the duplicates and deselect android platform in the inspector, Apply. Now try making a build.
     
  3. JustSuds

    JustSuds

    Joined:
    Jul 25, 2013
    Posts:
    7
    Thank you very much! :D That solved my issue entirely. I do wonder about the implications however, if one of the two plugins (Sentry or Firebase) needs to use a feature of the gson API that may be different between the two versions. But I guess I'll deal with that if it happens.
     
  4. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,983
    Luckily, the versions below 2.8 (around 2.4 i guess) are not compatible. But your plugins seems to use nearly same versions which are compataible.

    First see if any of the plugins included the dependency as an embedded one instead of resolving from resolver. Embedding the dependency is a bad practise and should be avoided. It's good to allow the resolution of dependencies to External Dependency Manager or gradle. Else, it ends up in duplicate libraries.

    If you find one of them embedding the jar, inform them to use External dependency manager for better compatibility with other plugins. I'm not sure if they actually listen though, but just to avoid future problems :)
     
  5. JustSuds

    JustSuds

    Joined:
    Jul 25, 2013
    Posts:
    7
    By your explanation, it seems like Sentry is the problem. I did find this one forum post on a different forum about this same issue, where they claimed "Sentry has done it correctly". But in their case, I think both vendors are probably doing the wrong thing, google is probably implementing this the correct way by using the external dependency manager.

    -> Cannot build due to multiple gson libraries - Pico Developer Answers (pico-interactive.com)

    Unity should probably have a better solution for this out of the box.
     
    Voxel-Busters likes this.
  6. Felicionato

    Felicionato

    Joined:
    Nov 9, 2015
    Posts:
    9
    OMG, this worked for me, I've been dealing with this for more than one day
     
    Voxel-Busters likes this.