Search Unity

How to find out where the *.jar comes that causes Duplicate class build issue

Discussion in 'Android' started by kaarloew, Mar 23, 2021.

  1. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    So problem is following, I tried to add yet another Android plugin to our project (which uses Unity 2019.4.20f1 ). Build step fails with following errors

    Duplicate class kotlin.BuilderInference found in modules kotlin-stdlib-1.3.11.jar (org.jetbrains.kotlin:kotlin-stdlib:1.3.11) and org.jetbrains.kotlin.kotlin-stdlib-1.3.72.jar (org.jetbrains.kotlin.kotlin-stdlib-1.3.72.jar)
    Duplicate class kotlin.Deprecated found in modules kotlin-stdlib-1.3.11.jar (org.jetbrains.kotlin:kotlin-stdlib:1.3.11) and org.jetbrains.kotlin.kotlin-stdlib-1.3.72.jar (org.jetbrains.kotlin.kotlin-stdlib-1.3.72.jar)
    .
    .

    The new plugin is using kotlin-stdlib-1.3.72, and that is correctly resolved with Unity JAR resolver. But I have no idea where the reference of kotlin-stdlib-1.3.11.jar comes. There isn't a file kotlin-stdlib-1.3.11.jar in my Unity project, but it seems that Temp/gradleOut/unityLibrary/build.gradle file has following line


    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11'


    So how can I figure out where the reference to kotlin-stdlib-1.3.11.jar comes from? And how to fix the issue?

    EDIT:
    It seems that the file comes from
    /Applications/Unity/Hub/Editor/2019.4.20f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/kotlin-stdlib-1.3.11.jar

    So how can I avoid the issue?
     
    Last edited: Mar 23, 2021
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Try exporting Android Studio project, maybe there you'll get hints on how to fix it. Probably you need to update the kotlin support library version in gradle script.
     
  3. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    I used IPostGenerateGradleAndroidProject to remove the
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11'
    from build.gradle, and that did the trick. I still don't have any idea where that line comes.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    I think it is added by Unity and probably needs updating. Could you report a bug for this?
     
  5. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    @karrloew I have the same issue here. Can you please share how you removed the Unity-included implementation, i.e. what does your IPostGenerateGradleAndroidProject?

    Thanks!
     
  6. Colin_MacLeod

    Colin_MacLeod

    Joined:
    Feb 11, 2014
    Posts:
    334
    xysverma likes this.
  7. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    What should I write to the bug report? Because it seems to only happen with certain plugins (and I only have one non public plugin that does this), e.g. Facebook Unity plugin adds org.jetbrains.kotlin.kotlin-stdlib-1.4.10.jar and that does not conflict (and also no
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.11'
    is added to the build.gradle in that case).
     
  8. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    What kind of plugin is that (precompiled archive or source code)? I think the kotlin stuff is only added to gradle when you have kotlin file as a plugin in your project.
    The bug report details are non-public and not shared with anyone, you can report bugs using private plugins too.
     
  9. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
    Thanks. I opened Case 1325245
     
  10. kaarloew

    kaarloew

    Joined:
    Nov 1, 2018
    Posts:
    360
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    So the main problem turns out to be that one your own .aar libraries pulls in Kotlin support and the one setup automatically by Unity is of different version and adds duplicate kotlin standard library. Unfortunately, there is one other issue: Unity include a rather old version of Kotlin, resulting in issues in Android Studio when trying to open exported project.
    To resolve your issue:
    - Export Android Studio project
    - Comment out all Kotlin stuff in gradle files
    - Open project in Android Studio
    - Uncomment Kotlin lines one by one
    - You don't need the "implementation" line with Kotlin stdlib, that one is pulled in by your other library
    - Change Kotlin version to the same one as used by that other library to resolve the duplicates
    - Finally, use resulting gradle files as templates in Unity project