ProGuard Warning: Unable to write resource (write to duplicate zip)

First of all, I know this question already exists on stackoverflow, but I can't seem to solve it, although I've tried suggestions like not using -injar, using packagesOptions, etc.

I know the release will work, but I like clean builds. When I create signed apks. After cleaning the project, I get the following errors:

Warning:can't write resource [.readme] (Duplicate zip entry [classes.jar:.readme])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [joda-time-2.8.1.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [joda-time-2.8.1.jar:META-INF/NOTICE.txt])

      

Sometimes commons-collections4-4.0.jar warnings appear instead of joda-time-2.8.1.jar (same .readme, license, notice).

I tried excluding those with packageOptions but that doesn't work.

Here is my build.gradle module

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude '.readme'
    }

    defaultConfig {
        applicationId 'com.example.myapp'
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName '0.1'
    }

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'org.apache.commons:commons-collections4:4.0'
    compile 'org.jsoup:jsoup:1.8.2'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.google.android.gms:play-services-gcm:7.5.0'
    compile 'joda-time:joda-time:2.8.1'
}

      

And my proguard-rules.pro file

# Defaults
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment

-keepnames class * implements java.io.Serializable

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    !private <fields>;
    !private <methods>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keepclasseswithmembernames class * {
    native <methods>;
}
-keepclassmembers class * {
    public void *ButtonClicked(android.view.View);
}

# Use this to prevent errors in builds.
# usage of org.joda.time in this app does not need org.joda.convert
-dontwarn org.joda.convert.**


# Remove logs. Only when using 'proguard-android-optimize.txt'
-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static int v(...);
    public static int i(...);
    public static int w(...);
    public static int d(...);
    public static int e(...);
}

      

Thanks in advance.

EDIT: As per the request for a possible duplicate warning ( Proguard warnings "cannot write resource [META-INF / MANIFEST.MF] (Duplicate zip entry)" ). The user who asked the question said they are using multiple modules (instead of one) and are not hosting any files (due to sensitive data), so I don't know if this is the same case. Also tried all possible options from the first answer and none of them worked. The other answers didn't work (except for the -dontwarn option, which I won't use for obvious reasons).

+3


source to share


1 answer


I'm sure you added this jar in two places.

1 # are in your library project 2 # are in your implementation project (which uses the library)



In this case, you can remove the jar from the implementation project as it will be packaged from the library.

Or .. maybe you added the jar to your classpath, android will get it automatically from the libs folder, so there is no need to add it to the classpath.

+1


source







All Articles