Search code examples
androidandroid-studiobuild.gradleandroid-proguard

(Duplicate zip entry [coolLib.jar:{pkg}/BuildConfig.class]))


I have an android project in Android Studio 2.3.0 beta4 which is dependent on a library project CoolLib.

CoolLib has its source in a jar file coolLib.jar in its libs folder. coolLib.jar contains file {pkg}/BuildConfig.class.

When i try to build and run the project in a device/emulator at Android API-22+, it runs perfectly but when i try to do the same on a device/emulator at API VERSION < 22, Android Studio fails to build with an Exception--

Warning: Exception while processing task java.io.IOException: Can't write [D:\AndroidStudioProjects\CoolProject\app\build\intermediates\transforms\proguard\debug\jars\3\1f\main.jar] (Can't read [D:\AndroidStudioProjects\CoolProject\CoolLib\build\intermediates\bundles\default\libs\coolLib.jar(;;;;;;**.class)] (Duplicate zip entry [coolLib.jar:{pkg}/BuildConfig.class])) :app:transformClassesAndResourcesWithProguardForDebug FAILED

The build.gradle of project contains the following versions of support lib etc.--

ext {
supportLibVer = '25.1.1'
playServiceVer = '10.0.1'

buildToolsVer = "25.0.2"

compileSdkVer = 25
targetSdkVer = 25
minSdkVer = 16
}


dependencies {
compile files('libs/FLurry_3.2.2.jar')
compile files('libs/jxl-2.6.12.jar')

compile project(':CoolLib')

compile files('libs/gcm.jar')
compile "com.google.android.gms:play-services-ads:$playServiceVer"
compile "com.android.support:appcompat-v7:$supportLibVer"
compile "com.android.support:design:$supportLibVer"
compile "com.android.support:cardview-v7:$supportLibVer"
compile "com.android.support:support-v13:$supportLibVer"
compile 'com.github.bumptech.glide:glide:3.7.0'
}

Solution

  • Ok, I got the solution.

    The Why-

    I compared the build steps in gradle console at API22(build OK) and API16(build fails). At API22, the console said-

    +Instant Run: Proguard is not compatible with instant run. It has been disabled for debug

    +Instant Run: Resource shrinker automatically disabled for debug

    ..and the build was successful. When i disabled InstantRun, it failed on API22 also.

    The Reason-

    The problem was in proguard configuration. The BuildConfig.class of coolLib.jar was defined to be kept in proguard-project.txt , so it was keeping all the .class files in that package but BuildConfig.class must be modified at build time according to the Main Project.

    The Solution-

    I removed that -keep statement and it works like a charm.