Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Android Build -> Multiple Dex Files Error -> Multiple dex files define Lcom/google/unity/BuildConfig

Discussion in 'Android' started by Deleted User, Jul 29, 2018.

  1. Deleted User

    Deleted User

    Guest

    Hi!

    I'm struggling to create a Unity build for Android (I'm new to Android as a platform). I get this error:

    ```
    Execution failed for task ':transformClassesWithDexForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/unity/BuildConfig;
    ```

    I cannot find the source of this problem and I've read through a multitude of stack overflow threads. How do I cut through the noise to find these DEX files and how do I find this com/google/unity/BuildConfig? I can't seem to find information on what com/google/unity/BuildConfig actually is either. Is it a package in the same way that com.example.package is?

    Is there any text that I need to read or concepts I need to understand in order to diagnose this properly?

    Cheers!
     
  2. JustasKavaliauskas

    JustasKavaliauskas

    Joined:
    Jan 20, 2014
    Posts:
    2
    Hey,
    I'm hoping this is Unity bug and will be resolved at some point, because I started getting this error after I updated my project to 2018.2.1f1 Unity version.
    To fix it you can try enabling Multidex, but after I did that, I got stuck on another issue, so I didn't bother anymore and returned to 2018.1.x - which works fine for me.
    Also you could just change Build System from Gradle to Internal (in File->Build Settings -> Build System), which worked for me too, but I wanted to stay with Gradle to have more control, so It made more sense to get back to 2018.1.
     
    divingcrash likes this.
  3. Deleted User

    Deleted User

    Guest

    Hey sRn!

    I just fixed the error this morning! Within Android studio at the Project level there's two folders, 'MyGameFolder' and 'External Libraries'. Within MyGameFolder there was a GoogleMobileAdsPlugin folder (which I'm surprised isn't an external library but hey ho). Within the GoogleMobileAdsPlugin folder, there are two folders -> build & libs.

    The error read as follows: "Multiple dex files define Lcom/google/unity/BuildConfig;"

    Inside of the build and libs folder, there were definitions of the buildConfig class. This DEX transform process creates android specific DEX class files from java classes, which are then packaged together with other resources to build an APK file.

    So since the error reads 'multiple dex files define com/google/unity/buildConfig' we can see that happening below in these two folders.

    GoogleMobileAdsPlugin > Build > Generated > Source > BuildConfig > Release
    upload_2018-7-31_7-52-50.png

    GoogleMobileAdsPlugin > libs
    upload_2018-7-31_7-54-24.png

    Notice how they both form the same package name: com.google.unity.ads.BuildConfig

    It appears as though when you do a build it tries to package the library folder and the release folder into a single APK, though I could be wrong as I'm not very knowledgable about android as a platform at all, I'm a total newbie at this point. But removing the libs folder solved the error presumably because you remove the two class definitions so that they no longer clash.

    I also guess if there is already a definition in build, then you don't need lib. I'd love to read some other people's thoughts on this as I have no idea if I've just made a really bad decision
    ⚆ _ ⚆

    So my advice to you is to look at the error, see what package it falls under and to go and look for that pattern within your folders and see if you can find a duplicate class definition being formed and remove the unneeded one.

    Really hurt my head trying to solve this one so I'm writing as much here as I can in the hopes it helps someone else as well as myself.

    Cheers!
     

    Attached Files:

    Starbox, Abrssh and neonblitzer like this.
  4. JustasKavaliauskas

    JustasKavaliauskas

    Joined:
    Jan 20, 2014
    Posts:
    2
    Thanks for sharing and digging deeper!
    But I didn't bother exporting gradle project, since it should work without doing so, however I do understand the problem, but what I don't understand is why this started happening with latest Unity version (unless you are not using 2018.2.1f1?? :eek:), because I don't want to keep fixing same errors with any other plugins while Unity is doing something weird :(.
    Anyways, I will keep an eye on this topic, but at the moment I'm good with 2018.1.6f1, also maybe you could try different unity version to see if this error persist?
     
  5. Astirian

    Astirian

    Joined:
    Apr 28, 2018
    Posts:
    15
    I'm so sick of wasting my life on this S***.
     
  6. KingKong320

    KingKong320

    Joined:
    Mar 2, 2018
    Posts:
    21
    same here
     
  7. Ponytech

    Ponytech

    Joined:
    Jun 13, 2016
    Posts:
    33
    May I say +1?
     
  8. Zynigma

    Zynigma

    Joined:
    Sep 23, 2012
    Posts:
    22
    Only if they'll accept my +1...
     
  9. oriontvv

    oriontvv

    Joined:
    Jun 19, 2016
    Posts:
    5
    I can't switch to internal build system, because there isn't such config option. I'm using gitlab-ci builds with dockerized unity. Any other suggestions?
     
  10. ponos_sanchez

    ponos_sanchez

    Joined:
    Aug 16, 2017
    Posts:
    2
    Any help for fix this?
     
  11. KingKong320

    KingKong320

    Joined:
    Mar 2, 2018
    Posts:
    21
    remove all the plugins,And then reimport all of them one by one and don't let duplicate jar. or aar. files of same name,this is wht worked for me.
     
  12. AAAAAAAAAE

    AAAAAAAAAE

    Joined:
    Jun 8, 2013
    Posts:
    100
    This worked for me
    credit to: https://www.spikything.com/blog/ind...ror-with-unityads-after-upgrading-to-unity-5/

    • Close Unity Editor
    • Backup your project
    • Remove any folder or meta file called UnityAds from your project’s Assets/Libs folder
    • Remove any folder or meta file called UnityAds from your project’s Assets/Plugins/Android folder
    • Start Unity
    • Build your project for Android
    If this doesn’t work, try doing an Assets > Reimport All, then building again. Hopefully, future version of Unity will solve this problem automatically. Good luck out there!
     
  13. oriontvv

    oriontvv

    Joined:
    Jun 19, 2016
    Posts:
    5
    @anileapen05, Man, you're awesome! It's works great for me after reimporting assets - unity has updated some meta file. You just saved me. Thanks!
     
    shekhsagorahamed and AAAAAAAAAE like this.
  14. AAAAAAAAAE

    AAAAAAAAAE

    Joined:
    Jun 8, 2013
    Posts:
    100
    Thanks man.
     
  15. theronv123

    theronv123

    Joined:
    Nov 17, 2016
    Posts:
    1
    @anileapen05 Thanks man! Your steps solved my problem as well. Much appreciated!
     
    AAAAAAAAAE likes this.
  16. ddsventure

    ddsventure

    Joined:
    Jul 6, 2018
    Posts:
    1
    I had the same issue and I think it was because I imported the Unity Monetization plugin from the asset store and also selected "Enable built-in Ads Extension" I fixed it by de-selecting "Enable built-in Ads Extension"
     
  17. innovativeapps14

    innovativeapps14

    Joined:
    Dec 17, 2018
    Posts:
    1
    I got the similar error after adding unity ads 3.0 . Any one know fix for this error?
     
  18. DarkKapo

    DarkKapo

    Joined:
    Dec 30, 2018
    Posts:
    1
    Heroe
     
    AAAAAAAAAE likes this.
  19. Ogeid

    Ogeid

    Joined:
    Apr 16, 2013
    Posts:
    5
    I did it too. I was hoping to use Admob + videos and banner from UnityAds. Everything was working perfectly, both the Admob plugin and UnityAds (videos). But after I imported this 3.0 package to use banner, I got this error.
     
  20. moscas99

    moscas99

    Joined:
    Jun 13, 2017
    Posts:
    7
    Solved!!!

    I just updated the Unity version today (January 29 2019), then build and it worked, I just got an error about Facebook but I was getting this error before the update to Unity and now it's there but the APK was built.

    PS: The Unity version that I installed today was 2018.3.3f1.
     
  21. moscas99

    moscas99

    Joined:
    Jun 13, 2017
    Posts:
    7
    It is solved now, just update to the new version of Unity, being this version (the one that worked for me today) the 2018.3.3f1, just got an error about facebook but it is still building.
     
  22. Mobazy

    Mobazy

    Joined:
    Jan 27, 2018
    Posts:
    9
    This worked for me too.. Services -> Ads -> Advanced -> Uncheck: Enable build-in Ads extension.
     
  23. toastertub

    toastertub

    Joined:
    Oct 28, 2013
    Posts:
    25
    LIFE SAVER!
     
    AAAAAAAAAE likes this.
  24. tagincorp2016

    tagincorp2016

    Joined:
    Jan 23, 2016
    Posts:
    2
    Do not forget to remove remaining unityads aar or other files while using built-in version.
     
  25. phapnq

    phapnq

    Joined:
    Jul 25, 2018
    Posts:
    1
    The error occurred after installing the FacebookAuDienceNetwork package. Hope everybody help please.
    upload_2019-11-7_16-55-50.png
     
  26. swats1010

    swats1010

    Joined:
    Jun 26, 2019
    Posts:
    11

    I tried above steps and tried to find the build config with this :
    find . -name '*.*' -exec grep -Hls BuildConfig {} \;

    If I remove temp folder then only result is this entry :
    ./Assets/Plugins/Android/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar


    But after build when i check then the BuildConfig file is in all these folders

    ./obj/Debug/Assembly-CSharp-Editor.dll.mdb

    ./obj/Debug/Assembly-CSharp-Editor.dll

    ./Ludo Online Chupamobile.Editor.csproj

    ./Temp/StagingArea/android-libraries/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar

    ./Temp/gradleOut/.gradle/4.0.1/taskHistory/fileSnapshots.bin

    ./Temp/gradleOut/.gradle/4.0.1/taskHistory/taskHistory.bin

    ./Temp/gradleOut/build/generated/source/buildConfig/debug/com/delusion/ludofun/BuildConfig.java

    ./Temp/gradleOut/build/intermediates/classes/debug/com/delusion/ludofun/BuildConfig.class

    ./Temp/gradleOut/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar

    ./Temp/gradleOut/GoogleMobileAdsPlugin/build/generated/source/buildConfig/release/com/google/unity/BuildConfig.java

    ./Temp/gradleOut/GoogleMobileAdsPlugin/build/intermediates/classes/release/com/google/unity/BuildConfig.class

    ./Temp/gradleOut/GoogleMobileAdsPlugin/build/intermediates/jniLibs/release/unity-plugin-library.jar

    ./Temp/gradleOut/GoogleMobileAdsPlugin/build/intermediates/bundles/default/classes.jar

    ./Temp/gradleOut/GoogleMobileAdsPlugin/build/intermediates/bundles/default/libs/unity-plugin-library.jar

    ./Library/LastBuild.buildreport

    ./Library/ScriptAssemblies/Assembly-CSharp-Editor.dll.mdb

    ./Library/ScriptAssemblies/Assembly-CSharp-Editor.dll

    ./Library/metadata/fc/fc20e706f6a354d9db2e099be3fa8efb.info

    ./.vs/Ludo Online/xs/sqlite3/storage.ide

    ./.vs/Ludo Online/xs/project-cache/Ludo Online.Editor-Debug.json

    ./Assembly-CSharp-Editor.csproj

    ./Ludo Online.Editor.csproj

    ./Assets/Plugins/Android/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar

    ./Assets/Chartboost/Editor/XCodeEditor/XCBuildConfiguration.cs

    ./Assets/Chartboost/Editor/XCodeEditor/XCodeEditorMenu.cs

    ./Assets/Chartboost/Editor/XCodeEditor/XCConfigurationList.cs

    ./Assets/Chartboost/Editor/XCodeEditor/XCProject.cs


    And i am unable to resolve it at all
     
  27. ddadkhah

    ddadkhah

    Joined:
    Nov 6, 2017
    Posts:
    59
    @anileapen05
    I have a question. How did you find this solution?
     
  28. reiserleo

    reiserleo

    Joined:
    Aug 1, 2020
    Posts:
    1

    Man you have saved my life, reimport all solve the problem for me, I was lost a full week in this, thank you
     
    AAAAAAAAAE likes this.