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

How to configure gradle to exclude unity-android-resources BuildConfig.class?

Discussion in 'Android' started by ilovebread, Jul 16, 2017.

  1. ilovebread

    ilovebread

    Joined:
    Jun 8, 2015
    Posts:
    6
    Hi guys,

    So I've recently upgraded my Unity to 5.6 in hopes of utilizing the Gradle build pipeline (to workaround the nasty dex limit).

    After some days of configuring it, I ran into this head-cracking issue. Here is the error as displayed in the Unity Editor console:

    Code (csharp):
    1.  
    2. Execution failed for task ':transformClassesWithJarMergingForRelease'.
    3. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: my/unity/game/BuildConfig.class
    4.  
    So it seems that some plugin/external project is including a BuildConfig class file with the exact same package name (as depicted by the file structure, and also why I had to set enforceUniquePackageName to false in the main project gradle).

    In Android Studio, when looking for the BuildConfig file, I noticed two different projects that had the same package name. One of the projects was definitely for the main Unity project, while the other was for an automatically generated/included project for unity-android-resources.

    This is the BuildConfig.java for the unity-android-resources project:

    Code (csharp):
    1.  
    2. /**

    3.  * Automatically generated file. DO NOT MODIFY

    4.  */
    5. package my.unity.game;
  

    6. public final class BuildConfig
    7. {
    8.      public static final boolean DEBUG = Boolean.parseBoolean("true");
    9.      public static final String APPLICATION_ID = “my.unity.game;
    10.      public static final String BUILD_TYPE = "debug";
    11.      public static final String FLAVOR = "";
    12.      public static final int VERSION_CODE = 1;
    13.      public static final String VERSION_NAME = "1.0";
    14. }
    15.  
    While this one is for the main project:

    Code (csharp):
    1.  
    2. /**

    3.  * Automatically generated file. DO NOT MODIFY

    4.  */
    5. package my.unity.game;
  

    6. public final class BuildConfig
    7. {
    8.      public static final boolean DEBUG = Boolean.parseBoolean("true");
    9.      public static final String APPLICATION_ID = “my.unity.game;
    10.      public static final String BUILD_TYPE = "debug";
    11.      public static final String FLAVOR = "";
    12.      public static final int VERSION_CODE = 72;
    13.      public static final String VERSION_NAME = "2.04.34";
    14. }
    15.  
    Is there a way I could somehow either:

    • Exclude the BuildConfig.java from the automatically generated unity-android-resources project via the main gradle file? or,

    • Is there someway I could alter the package name for the automatically generated BuildConfig.java file for unity-android-resources?
    If it helps, here are the dependencies (and no, doesn't seem like I can just remove unity-android-resources dependency, as the build fails due to some missing icon resources):

    Code (csharp):
    1.  
    2. dependencies {
    3.      compile fileTree(dir: 'libs', include: ['*.jar'])
    4.      compile(name: 'GoogleAIDL', ext:'aar')
    5.      compile(name: 'GooglePlay', ext:'aar')
    6.      compile(name: 'appcompat-v7-23.4.0', ext:'aar')
    7.      compile(name: 'cardview-v7-23.4.0', ext:'aar')
    8.      compile(name: 'common', ext:'aar')
    9.      compile(name: 'facebook-android-sdk-4.23.0', ext:'aar')
    10.      compile(name: 'facebook-android-wrapper-7.10.0', ext:'aar')
    11.      compile(name: 'play-services-ads-10.0.1', ext:'aar')
    12.      compile(name: 'play-services-auth-10.0.1', ext:'aar')
    13.      compile(name: 'play-services-auth-base-10.0.1', ext:'aar')
    14.      compile(name: 'play-services-base-10.0.1', ext:'aar')
    15.      compile(name: 'play-services-basement-10.0.1', ext:'aar')
    16.      compile(name: 'play-services-drive-10.0.1', ext:'aar')
    17.      compile(name: 'play-services-games-10.0.1', ext:'aar')
    18.      compile(name: 'play-services-iid-10.0.1', ext:'aar')
    19.      compile(name: 'play-services-nearby-10.0.1', ext:'aar')
    20.      compile(name: 'play-services-tasks-10.0.1', ext:'aar')
    21.      compile(name: 'support-v4-24.0.0', ext:'aar')
    22.      compile project(':Etcetera_lib')
    23.      compile project(':Flurry_lib')
    24.      compile project(':MainLibProj')
    25.      compile project(':PermissionCheckPlugin')
    26.      compile project(':SwrvePush_lib')
    27.      compile project(':fyber-unityads-1.5.6-r3')
    28.      compile project(':unity-android-resources') // <- possible cause of error
    29. }
    30.  
    Thanks for any help guys.
     
    Qbit86 likes this.
  2. ilovebread

    ilovebread

    Joined:
    Jun 8, 2015
    Posts:
    6
    Okay, so I think I solved this by specifying packageBuildConfig = false inside the android block in [Unity root]/PlaybackEngines/AndroidPlayer/Tools/GradleTemplate/libTemplate.gradle
     
    potu likes this.
  3. GunLengend

    GunLengend

    Joined:
    Sep 24, 2014
    Posts:
    54
    Well, first i want to say hello @ilovebread .
    Then, sadly, i'm facing same problem like you and try to add solution above. But unfortunately, i got error :
    A problem occurred evaluating root project 'gradleOut'.
    > Cannot set the value of read-only property 'packageBuildConfig' for object of type com.android.build.gradle.AppExtension.


    Please help me figure it out, thank a lot
     
    Qbit86 likes this.
  4. MarsZhan

    MarsZhan

    Joined:
    Apr 22, 2015
    Posts:
    2