asifa
asifa

Reputation: 771

proguard - Duplicate zip entry classes.jar

I am unable to build signed apk. I implemented this library into my project: https://github.com/anjlab/android-inapp-billing-v3

after I implemented it, when I try to generate apk this error appears:

    Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Can't write [C:\Users\Admin\StudioProjects\MealPlanner\app\build\intermediates\transforms\proguard\release\jars\3\1f\main.jar] (Can't read [C:\Users\Admin\StudioProjects\MealPlanner\app\build\intermediates\exploded-aar\com.android.billingclient\billing\1.0\jars\classes.jar(;;;;;;**/*.class)] (Duplicate zip entry [classes.jar:com/android/vending/billing/IInAppBillingService$Stub$Proxy.class]))

I don't have any aidl file in my project and I tried outjars and exluding it from build.gradle but still the problem persists.

Any ideas how to solve this?

Upvotes: 0

Views: 2093

Answers (2)

Kees Dil
Kees Dil

Reputation: 26

When i was trying to build an in-app billing app for Google play (based on their TrivialDrive sample) in Android Studio 3.2.1, buildtools version 28.0.3, i also found that generation of the signed release APK was blocked by Java.IO.Exception, transformClassesAndResourcesWithProguardForRelease, duplicate zip entry classes etcetera ...

First i followed recommendations on the internet to adapt the proguard pro file, then i updated the buildtools version, changed my gradle file many times, nothing helped!

The strange thing is that there was no problem with the original trivialdrive sample build 2 weeks ago with dependencies including 'com.android.billingclient:billing:1.1'.

After deleting implementation 'com.android.billingclient:billing:1.1', the build was successful! So i think something was changed for in-app billing dependency requirements??

Upvotes: 1

Atul
Atul

Reputation: 4320

I faced this issue recently after I added third party library (open source) and spend really many hours struggling to get through. Stack overflow has many questions and discussion around it. Everyone has suggested different solution However I followed this one which suggested to correct version numbers. But that alone did not solve my problem.

Since my case was same like yours (that is "Duplicate zip entry" and "java.io.IOException: Can't write") I thought to answer your question.

Here is what I did (other than version changes as mentioned above):

In the build.gradle of library that you've added, add this:

buildTypes
{
    release
    {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'billing-proguard-rules.pro'
    }

    debug
    {
        minifyEnabled false
        shrinkResources false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'billing-proguard-rules.pro'
    }
}

And your billing-proguard-rules.pro should look something like this:

-keep public class * extends com.anjlab.android.iab.v3.** { *; }
-keepclassmembernames class * extends com.anjlab.android.iab.v3.** { *; }

Since billing library you imported is open source (like same is my case) it is fine to keep it as it is.

You are ready to go!

Upvotes: 0

Related Questions