Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Error building APK on Android Studio: duplicate entry

Discussion in 'Android' started by magarcias, Jul 28, 2016.

  1. magarcias

    magarcias

    Joined:
    Jul 20, 2016
    Posts:
    2
    In our project we have reached the 64k method limit and decided to try building our game using Android Studio so we could use the multidex option. Following the process detailed in the Unity manual, we have found the exported project won't build on Android Studio as exported (and this is a version that was built ok directly from Unity).
    In Android Studio 2.1.2 we import the generated project using the default options (the manual doesn't mention what are the right import options). The errors we get on building the project to generate an APK are:

    * the app_name string used in the Manifest couldn't be found (we fixed by hardcoding it)

    * the number of method references was > 64k even though the same project built fine on Unity (so we had to enable Multidex to be able to build it, after this Make Project completed with no error)

    * and finally the one we're stuck with, after a successful Make Project, if we try Build APK, we get an error:
    "FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':titanBrawl:transformClassesWithJarMergingForDebug'.
    > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/unity/purchasing/BuildConfig.class
    "
    Searching on several forums, apparently this error comes from duplicate entries in the .jar files included in the project, which we can't really replace since the files are exported from Unity. We've tried commenting out a few of the compile project lines on build.gradle, which allows to build the APK but it obviously won't run since it's missing necessary methods.

    For more info: we're on Unity 5.3.6f1, Android Studio 2.1.2, latest Android SDK (24). The generated build.gradle file for the main project looks like this:

    apply plugin: 'com.android.application'android {
    compileSdkVersion 24buildToolsVersion "24.0.1"defaultConfig {
    applicationId "com.omnidrone.lanes"minSdkVersion 18targetSdkVersion 24multiDexEnabled true}

    buildTypes {
    release {
    minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'}
    }

    dexOptions {
    incremental truejavaMaxHeapSize "4g"}
    }

    dependencies {
    compile project(':appcompat')
    compile project(':cardview')
    compile project(':common')
    compile project(':design')
    compile project(':facebookandroidsdk482')
    compile project(':facebookandroidwrapperrelease')
    compile project(':googlePlay')
    compile project(':helpshift')
    compile project(':mainLibProj')
    compile project(':native_plugins_lib')
    compile project(':playservicesbase840')
    compile project(':playservicesgames840')
    compile project(':playservicesgcm840')
    compile project(':playservicesplus840')
    compile project(':recyclerview')
    compile project(':unityadsrelease')
    compile project(':voxelbusters_utility_lib')
    compile project(':vungle_lib')
    compile 'com.android.support:support-v4:24.1.1'compile 'com.google.android.gms:play-services:+'compile files('libs/AF-Android-SDK.jar')
    compile files('libs/AppsFlyerAndroidPlugin.jar')
    compile files('libs/com-google-code-gson_gson.jar')
    compile files('libs/dagger.jar')
    compile files('libs/javax.inject.jar')
    compile files('libs/json-simple-1.1.1.jar')
    compile files('libs/omniata-android-sdk.jar')
    compile files('libs/unity-classes.jar')
    compile files('libs/UnityAndroidExtension.jar')
    compile 'com.android.support:multidex:1.0.0'}

    Any help regarding this issue would be highly appreciated, since all other forum threads regarding this error were apparently related to specific libraries, which we have ruled out, since apparently the unity-generated libraries themselves seems to be the ones triggering this error.
     
  2. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,071
    Thank you for reporting this. If I remember correctly, BuildConfig can be safely removed from IAP plugin. You could try doing it manually.

    Are you getting any issues if you remove it and run on the device?

    In the meanwhile, I'll check with IAP team.
     
  3. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    I have tested the following successfully in Unity 5.4.

    1. Create a new project, enable and import Unity IAP
    2. Export to android studio, including the IAP Demo scene
    3. Build and runs successfully from android studio

    Can you retest under Unity 5.4? There were a number of export issues fixed in 5.4.
     
  4. AlexWitcher

    AlexWitcher

    Joined:
    Aug 11, 2013
    Posts:
    3
    Hi, magarcias, Have you solved a problem? I have the same problem, but i have duplicate entries exeptions for almost all project dependencies, also for com/unity/purchasing. i use Unity 5.4, it is main project build.gradle:


    Code (JavaScript):
    1. apply plugin: 'com.android.application'
    2.  
    3. android {
    4.     compileSdkVersion 24
    5.     buildToolsVersion "24.0.1"
    6.     lintOptions {
    7.         abortOnError false
    8.     }
    9.     defaultConfig {
    10.         applicationId "com.blablabla.balblablabla.android.gplay"
    11.         minSdkVersion 15
    12.         targetSdkVersion 23
    13.         multiDexEnabled true
    14.     }
    15.  
    16.     buildTypes {
    17.         release {
    18.             minifyEnabled false
    19.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    20.         }
    21.     }
    22. }
    23.  
    24. dependencies {
    25.     compile project(':adnetworkacrelease')
    26.     compile project(':adnetworkalrelease')
    27.     compile project(':adnetworkasrelease')
    28.     compile project(':adnetworkimrelease')
    29.     compile project(':adnetworkl1release')
    30.     compile project(':adnetworklbrelease')
    31.     compile project(':adnetworkm2release')
    32.     compile project(':adnetworkmraidrelease')
    33.     compile project(':adnetworknxrelease')
    34.     compile project(':adnetworku1release')
    35.     compile project(':adnetworkvastrelease')
    36.     compile project(':amazonAppStore')
    37.     compile project(':cardviewv72340')
    38.     compile project(':common')
    39.     compile project(':facebookandroidsdk4140')
    40.     compile project(':facebookandroidwrapper000')
    41.     compile project(':firebasecommon940')
    42.     compile project(':fusesdkcommonrelease')
    43.     compile project(':fusesdkrelease')
    44.     compile project(':fuseUnityBridge')
    45.     compile project(':googleAIDL')
    46.     compile project(':googlePlay')
    47.     compile project(':mainLibProj')
    48.     compile project(':mopubsdkrelease')
    49.     compile project(':notifications')
    50.     compile project(':playservicesads940')
    51.     compile project(':playservicesadslite940')
    52.     compile project(':playservicesanalytics940')
    53.     compile project(':playservicesanalyticsimpl940')
    54.     compile project(':playservicesauthbase940')
    55.     compile project(':playservicesbase940')
    56.     compile project(':playservicesbasement940')
    57.     compile project(':playservicesclearcut940')
    58.     compile project(':playservicesdrive940')
    59.     compile project(':playservicesgames940')
    60.     compile project(':playservicesgass940')
    61.     compile project(':playservicesnearby940')
    62.     compile project(':playservicestasks940')
    63.     compile project(':recyclerviewv72340')
    64.     compile project(':supportv42340')
    65.     compile project(':unityads')
    66.     compile project(':unityandroidresources')
    67.     compile files('libs/androidannotations-api-3.3.1.jar')
    68.     compile files('libs/bolts-android-1.4.0.jar')
    69.     compile files('libs/bolts-applinks-1.4.0.jar')
    70.     compile files('libs/bolts-tasks-1.4.0.jar')
    71.     compile files('libs/eventbus-2.4.0.jar')
    72.     compile files('libs/FlurryAnalytics.jar')
    73.     compile files('libs/gson-2.6.2.jar')
    74.     compile files('libs/jsr311-api-1.1.1.jar')
    75.     compile files('libs/liboffers.jar')
    76.     compile files('libs/libterms.jar')
    77.     compile files('libs/mopub-volley-1.1.0.jar')
    78.     compile files('libs/offersunity.jar')
    79.     compile files('libs/org.restlet.ext.gson.jar')
    80.     compile files('libs/org.restlet.jar')
    81.     compile files('libs/support-annotations-23.4.0.jar')
    82.     compile files('libs/termsunity.jar')
    83.     compile files('libs/TuneMarketingConsoleSDK-4.1.2.jar')
    84.     compile files('libs/TUNEUnityUtils.jar')
    85.     compile files('libs/unity-classes.jar')
    86.     compile 'com.android.support:multidex:1.0.1'
    87. }
    88.  
    I will be very glad of any help..
     
  5. magarcias

    magarcias

    Joined:
    Jul 20, 2016
    Posts:
    2
    I'm afraid we haven't found a solution so far, we still have to upgrade to Unity 5.4, but what you're describing is basically the same error we had. We'll post any updates we may have in case we find something.

     
  6. ipulCrimx

    ipulCrimx

    Joined:
    Aug 9, 2016
    Posts:
    3
    Hi, I got the very same problem. almost all of dependencies have duplicate issues. When I remove it one by one the apk is builded successfully, but when I install it the game obviously error since all dependencies are removed.
    I dont know if this will help or not, but this is my build.gradle's content
    Code (CSharp):
    1. apply plugin: 'com.android.application'
    2.  
    3. android {
    4.     compileSdkVersion 24
    5.     buildToolsVersion "25.0.2"
    6.  
    7.     defaultConfig {
    8.         applicationId [MY APPLICATION ID]
    9.         minSdkVersion 15
    10.         targetSdkVersion 24
    11.         multiDexEnabled true
    12.     }
    13.  
    14.     buildTypes {
    15.         release {
    16.             minifyEnabled false
    17.             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    18.         }
    19.     }
    20. }
    21.  
    22. dependencies {
    23.     compile project(':animatedvectordrawable2340')
    24.     compile project(':cardviewv72340')
    25.     compile project(':common')
    26.     compile project(':customtabs2340')
    27.     compile project(':facebookandroidsdk4170')
    28.     compile project(':facebookandroidwrapper790')
    29.     compile project(':googleAIDL')
    30.     compile project(':googlePlay')
    31.     compile project(':onesignalunity')
    32.     compile project(':oneSignalConfig')
    33.     compile project(':playservicesads1001')
    34.     compile project(':playservicesadslite1001')
    35.     compile project(':playservicesanalytics1001')
    36.     compile project(':playservicesanalyticsimpl1001')
    37.     compile project(':playservicesbase1001')
    38.     compile project(':playservicesclearcut1001')
    39.     compile project(':playservicesgass1001')
    40.     compile project(':playservicesgcm1001')
    41.     compile project(':playservicesiid1001')
    42.     compile project(':playserviceslocation1001')
    43.     compile project(':playservicestagmanagerv4impl1001')
    44.     compile project(':playservicestasks1001')
    45.     compile project(':supportv42400')
    46.     compile project(':supportvectordrawable2340')
    47.     compile project(':unityadsrelease')
    48.     compile 'com.google.android.gms:play-services:+'
    49.     compile 'com.android.support:appcompat-v7:24.2.1'
    50.     compile files('libs/bolts-android-1.4.0.jar')
    51.     compile files('libs/bolts-applinks-1.4.0.jar')
    52.     compile files('libs/bolts-tasks-1.4.0.jar')
    53.     compile files('libs/gameanalytics.jar')
    54.     compile files('libs/support-annotations-23.4.0.jar')
    55.     compile files('libs/unity-classes.jar')
    56.     compile files('libs/UnityAdsAdapter.jar')
    57.     compile files('libs/unity-plugin-library.jar')
    58. }
    59.  
     
  7. AdnanMauGames

    AdnanMauGames

    Joined:
    Jan 31, 2017
    Posts:
    3
    Till now i have the same issue .. is there any one got a solution for this problem ?
     
  8. JeanMeyblum

    JeanMeyblum

    Joined:
    Jan 22, 2014
    Posts:
    4
    I had the same issue.

    The fix was to put packageBuildConfig = false in the android { ... } section of the build.gradle files for each library project:

    Code (csharp):
    1.     android {
    2.         packageBuildConfig = false
    3.     ...
    Even if it's been depreceated it still working.

    The other solution is to specify a minSdkVersion greater or equals to 21 but your game won't be to play on older Android version (lower than Android 5.0).
     
  9. Apoll0

    Apoll0

    Joined:
    Jun 11, 2015
    Posts:
    16
    Got Cannot set the value of read-only property 'packageBuildConfig' for object of type com.android.build.gradle.AppExtension. error
     
  10. Ci_Yuan_Drunk

    Ci_Yuan_Drunk

    Joined:
    Aug 28, 2017
    Posts:
    1

    I had the same issue.

    The fix was to put packageBuildConfig = false in the android { ... }
    Got Cannot set the value of read-only property 'packageBuildConfig' for object of type com.android.build.gradle.AppExtension. error
     
  11. unitynewb

    unitynewb

    Joined:
    Feb 22, 2009
    Posts:
    235
    Did you fix it? I had the same error and got the read-only property message when I tried to change the packageBuildConfig setting.
     
    lilboylost and Qbit86 like this.
  12. Durston88

    Durston88

    Joined:
    Mar 15, 2012
    Posts:
    110
    Hi, just wondering if anyone on this thread had made any progress with this issue.
     
  13. TijsVdV

    TijsVdV

    Joined:
    Mar 7, 2017
    Posts:
    12
    We currently have the same issue but then in Unity. We recently decided to switch to UnityAds. I removed our old monitization platform and added UnityAds. In the editor everything works fine. But when we try to build to Android (we need gradle) we get this error: com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/unity3d/ads/IUnityAdsListener.class

    None of the above solutions worked.
     
  14. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    265
    Put
    Putting it under
    Code (csharp):
    1.  UnityApp/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/libTemplate
    worked for me on mac.
    Wondering Is there any better solution? As it still fails on cloud build?
     
  15. enesunco

    enesunco

    Joined:
    Apr 4, 2018
    Posts:
    9
    If you're using ad mediation, like we do with ironSrc, "Go to Ads settings and make sure “Enable built-in Ads extension” is unchecked, This step is necessary since iS UnityAds adapter already bundles the UnityAds SDK".

    https://developers.ironsrc.com/ironsource-mobile/unity/unityads-mediation-guide/#step-4
     
  16. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,303
    The non deprecated solution is to put this section next to the android section

    Code (CSharp):
    1. afterEvaluate {
    2.     generateReleaseBuildConfig.enabled = false
    3. }
     
    Yury-Habets likes this.