Exclude class from cross-project dependency via Gradle

Viewed 565

I've recently upgraded to Unity 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:

Execution failed for task ':transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: my/unity/game/BuildConfig.class

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 included project: unity-android-resources.

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):

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile(name: 'GoogleAIDL', ext:'aar')
     compile(name: 'GooglePlay', ext:'aar')
     compile(name: 'appcompat-v7-23.4.0', ext:'aar')
     compile(name: 'cardview-v7-23.4.0', ext:'aar')
     compile(name: 'common', ext:'aar')
     compile(name: 'facebook-android-sdk-4.23.0', ext:'aar')
     compile(name: 'facebook-android-wrapper-7.10.0', ext:'aar')
     compile(name: 'play-services-ads-10.0.1', ext:'aar')
     compile(name: 'play-services-auth-10.0.1', ext:'aar')
     compile(name: 'play-services-auth-base-10.0.1', ext:'aar')
     compile(name: 'play-services-base-10.0.1', ext:'aar')
     compile(name: 'play-services-basement-10.0.1', ext:'aar')
     compile(name: 'play-services-drive-10.0.1', ext:'aar')
     compile(name: 'play-services-games-10.0.1', ext:'aar')
     compile(name: 'play-services-iid-10.0.1', ext:'aar')
     compile(name: 'play-services-nearby-10.0.1', ext:'aar')
     compile(name: 'play-services-tasks-10.0.1', ext:'aar')
     compile(name: 'support-v4-24.0.0', ext:'aar')
     compile project(':Etcetera_lib')
     compile project(':Flurry_lib')
     compile project(':MainLibProj')
     compile project(':PermissionCheckPlugin')
     compile project(':SwrvePush_lib')
     compile project(':fyber-unityads-1.5.6-r3')
     compile project(':unity-android-resources') // <- possible cause of error
}

Thanks for any help guys.

0 Answers
Related