Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Android Project - Multiple dex files define Lcom/android/vending/billing/BuildConfig

Discussion in 'Android' started by Sebrofjr, Jun 3, 2016.

  1. Sebrofjr

    Sebrofjr

    Joined:
    Oct 1, 2014
    Posts:
    24
    I have been trying to export an Google Android Project from Unity so I can integrate an external library with Gradle.

    I am using :
    - Unity 5.4 Beta 18 OSX
    - Android Studio 2.1.1

    I had first attempted to use Unity 5.3.4 & 5.3.5 but it was crashing on launch in what appeared to be an issue with the Unity IAP export when building a Google Android Project. A bit of research lead me to believe that the issue was resolved in the latest 5.4 Beta, however now I am getting a Multiple define error when building.

    Something signigant has changed as now I have a googleAIDL, googlePlay, and unity adsrelease folders.
    • cupcakeTest
    • common
    • googleAIDL
    • googlePlay
    • unityadsrelease
    • unityandroidresources
    • Gradle Scripts

    The error the gradle build is failing on:

    Error:Error converting bytecode to dex:
    Cause: com.android.dex.DexException: Multiple dex files define Lcom/android/vending/billing/BuildConfig;

    Error:Execution failed for task ':cupcakeDigital:transformClassesWithDexForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

    When trying to remove this particular class it just moved onto the next one and repeat the error again. Is this a Unity issue with IAP and Ads or could this be something specific with my project?

    If I build just to an APK from Unity it works fine but then i cannot implement the external SDK. I can also export a test scene without Ads or IAP enabled and it does work in Project. I will try and enable those next to see if it is specifically these addons.
     
  2. Sebrofjr

    Sebrofjr

    Joined:
    Oct 1, 2014
    Posts:
    24
    After a few more tests on a fresh project I have confirmed that once you turn on Unity IAP in the services panel this error will occur in your google android project. These last few tests were with Unity 5.3.5p1 and 5.4.0b20.

    I will file a bug and in the meantime try and find a workaround.
     
  3. Sebrofjr

    Sebrofjr

    Joined:
    Oct 1, 2014
    Posts:
    24
  4. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,534
    I'm not using Unity IAP, I get this
    Error:Error converting bytecode to dex:
    Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
     
  5. andyisbonza

    andyisbonza

    Joined:
    Nov 26, 2012
    Posts:
    1
    Hey Sebrofjr, did you ever find a workaround?
    I am having this exact issue :(

    Thanks
    Andrew
     
  6. oslav

    oslav

    Joined:
    Jun 2, 2015
    Posts:
    3
    Hi, guys! Is there any solution? Thanks
    I can confirm, it's not generated by Unity IAP :(
     
  7. tanveerm

    tanveerm

    Joined:
    Feb 24, 2016
    Posts:
    22
    Hi,
    I'm also having similar issue. not able to make apk file from Android Studio.

    I'm using
    - Unity 5.3.5p7 with Unity IAP
    - Gradle 2.14.1
    - Android Studio V_2.2.2

    Help would be appreciated.
    Thanks
     
  8. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    652
    As a temporary workaround, you may delete the BuildConfig.class from within the .jar in Unity IAP plugin.
     
    rsodre likes this.
  9. tanveerm

    tanveerm

    Joined:
    Feb 24, 2016
    Posts:
    22
    @Yury-Habets , is it really happening from Unity IAP? if I delete BuildConfig.class,what impact will it have on IAP purchases?

    Thanks,
    Tanveer.
     
  10. oslav

    oslav

    Joined:
    Jun 2, 2015
    Posts:
    3
    @tanveerm, that would have actually no impact. This class is auto-generated and contains information about the configuration(tools versions) of the build.
    @Yury-Habets, I'm not using Unity IAP. But, I have: Facebook, OpenIAB, Fyber, Helpshift, NativeLibrary and a couple more plugins in the project.

    The temporary solution for me(as I really need to have all my plugins in the project) was to remove BuildConfig class from the .jars with the help of WinRar.
     
  11. ciobanu_pf

    ciobanu_pf

    Joined:
    Dec 10, 2015
    Posts:
    1
    This worked for me too, thank you! I just searched the whole project structure exported from Unity for "*.jar" and then just searched for BuildConfig class in every .jar file and deleted every occurence. Then I imported and built my project in AndroidStudio, and it worked, no more exceptions.
     
  12. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    285
    Any normal solution for this issue?
     
  13. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    652
    I asked the developer for an update.
     
    nicholasr and Qbit86 like this.
  14. nicholasr

    nicholasr

    Unity Technologies

    Joined:
    Aug 15, 2015
    Posts:
    108
    @Qbit88 @andyisbonza @tanveerm We suspect the Unity 5.3-era Exporter's transformation of the Java archives (AARs) made it more likely to see a duplicate symbol build problem later in this case's build pipeline.

    We're not planning on stripping the BuildConfig classes, currently: Unity IAP does include a BuildConfig.class in some of its AARs and another copy seems to have been injected somewhere in the 5.3/5.4-era "ADT" (considering retiring this soon) exporter, or possibly by a latter phase in the build toolchain after Unity. (Thanks to @Sebrofjr for the repro detail in his case.)

    I believe a resolution can be found in Unity 5.5's "Gradle export" (versus the 5.3-era "ADT export"). It could resolve this particular duplicate class vulnerability since there is no transformation of the AARs; they are kept intact as the sole source of these Java classes for the latter steps of the build chain, Android Studio in this case.

    Also, the workaround of performing a kind of "ZIP surgery" on the classes.jar enclosed within the various AARs and stripping the BuildConfig.class, should also still work. I believe this would be unnecessary with Unity 5.5's Gradle export however.
     
  15. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    285
    I've hit this issue exactly migrating from “Build System: Internal (Default)” to “Build System: Gradle (New)” (with no export at first). I have not tried “Build System: ADT (Legacy)”. Unity 5.5.4f1.
     
  16. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    112
    As said before, removing BluildConfig from the Unity jar solves the issue.
    In my case, the conflict started after adding the Kochava SDK.
    On a mac, you do it like this:

    Code (CSharp):
    1. # Removing duplicated class [B]BuildClass[/B]
    2. # List classes from JAR files
    3. $ cd Assets
    4. $ find . -name '*.jar' -exec grep -Hls BuildConfig {} \;
    5. ./Plugins/Android/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar
    6. ./Plugins/Android/KochavaSDK.jar
    7. # Remove class
    8. $ zip -d ./Plugins/Android/GoogleMobileAdsPlugin/libs/unity-plugin-library.jar "*/BuildConfig.class
     
    nicholasr likes this.
  17. dustinandrew

    dustinandrew

    Joined:
    Apr 30, 2010
    Posts:
    84
    For anyone looking to solve this issue here is what I added in each Android plugin's gradle:

    Code (CSharp):
    1.  
    2. task removeBuildConfig(dependsOn: "compileReleaseSources") {
    3.     doFirst {
    4.         file("$buildDir/intermediates/classes/release/pathToFile/BuildConfig.class").delete()
    5.     }
    6. }
    7.  
     
  18. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    234
    Did you change the pathToFile part in the path or just put it in like that?
     
  19. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    285
    I'm using Unity 2017.2.0f2 Gradle and still get Duplicate zip entry ...BuildConfig.class
    Code (csharp):
    1. Execution failed for task ':transformClassesAndResourcesWithProguardForRelease'.
    2. > java.io.IOException: Can't write [...\Temp\gradleOut\build\intermediates\transforms\proguard\release\jars\3\1f\main.jar] (Can't read [...\Temp\gradleOut\build\intermediates\exploded-aar\gradleOut\UnityOBBDownloader\unspecified\jars\classes.jar(;;;;;;**/*.class)] (Duplicate zip entry [classes.jar:com/unity3d/player/BuildConfig.class]))
     
  20. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    285
    @nicholasr Have you ever tried building Android-games with Gradle instead of legacy internal build system?