5

First of all I know that this question already exists in stackoverflow, but I can't solve it, although I tried suggestions like not using -injar, using packagingOptions, etc

I know the release is going to work, but I like clean builds. When I generate signed apks. After a project clean, I get those 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 instead of joda-time-2.8.1.jar there is commons-collections4-4.0.jar (same .readme, licence, notice) warnings.

I tried excluding those with packagingOptions, but it doesn't work.

Here is my module's build.gradle

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 requested from a possible duplicate warning (Proguard warnings "can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry)"). User that asked the question, said he is using multiple modules (instead of one) and did not post any files (due to sensitive data), so I don't know if its the same case. Also tried all possible options from the first answer and none of them worked. Other answers didn't work either (except the -dontwarn option which I am not going to use for obvious reasons).

Community
  • 1
  • 1
tchar
  • 838
  • 9
  • 12
  • possible duplicate of [Proguard fails with "can't write resource \[META-INF/MANIFEST.MF\] (Duplicate zip entry)"](http://stackoverflow.com/questions/16357959/proguard-fails-with-cant-write-resource-meta-inf-manifest-mf-duplicate-zip) – Jared Burrows Jul 29 '15 at 22:39
  • Indeed. Seems a duplicate, but since there was not any build.gradle file, or gradle rules, I didn't know if it was the same case as me. Tried some of the options though and it didn't work. – tchar Jul 29 '15 at 22:49

1 Answers1

2

I'm pretty sure you have this jar added on two locations.

1# are at your library project 2# are at your implementation project (that uses the library)

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

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

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • I only specify those dependencies in gradle (maven), as shown above. The app contains only one module and inside app/libs there is only aniqroid.jar (which is not duplicate). I searched the whole project folder, and there is not anything like joda-time.jar or apache-commons.jar. When I open the project structure window, there is only Sdk Location, Project and app, no libraries, or other modules except maven dependencies and aniqroid.jar inside app/libs. – tchar Jul 29 '15 at 22:12
  • I am back after doing some digging into files, etc. As for the duplicate .readme, I found the issue. I searched into sdk folder in appcompat-design and appcompat-v7 and I found that inside the respective .aar files there is a class.jar file that contains a .readme file in both design and v7. You can reproduce a part of my initial problem, by creating an empty project (just a main activity) and using this in build.gradle http://pastebin.com/YU560ckN and this in proguard-rules.pro http://pastebin.com/BFjwrYzc . If you add the rest dependencies (no jars) you get all the warnings. Can you confirm? – tchar Jul 30 '15 at 15:11
  • Same problem even i don't use proguard. after getting the above comment- i simply remove appcombat-v7 from dependencies - that solved the problem. try yourself please... – Banee Ishaque K Jul 20 '17 at 20:31