4

I'm trying to configure proguard and have faced with some problems which are sorted by priority:

  • I have received warnings of duplicates zip and cannot fix it. I use external libraries in "libs" directory and 2 library projects(one library project has one external lib - added to project only once) which are added to project only once. I tried to move my external jars to another directory, i.e. "lib" - just rename due to some users have been managed to solve it so but it doesn't help me. Another way was trying to implement custom_rules to basic build.xml due to it helps some users to avoid these warning. But everything from it doesn't help me, how can I fix it? Log:

    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-annotations-2.1.4.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [android-support-v4.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [google-analytics-v2.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [jackson-core-2.1.4.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [httpclientandroidlib-1.1.2.jar:META-INF/MANIFEST.MF])
    ProGuard: Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [deviceprint-lib-1.0.0.jar:META-INF/MANIFEST.MF])
    
  • Last thing is some notes during signed apk building:

    ProGuard: Note: com.google.analytics.tracking.android.AdHitIdGenerator: can't find dynamically referenced class com.google.ads.AdRequest
    ProGuard: Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
    ProGuard: Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
    

Full proguard file:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

# Otherwise return Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn com.fasterxml.jackson.databind.**

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

# Preserve all fundamental application classes.
-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.view.View
-keep public class * extends android.preference.Preference
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

# Preserve ActionBarSherlock and Android support libraries` classes and interfaces
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }

# Preserve all Jackson library classes
-keep class com.fasterxml.jackson.** { *; }

# Original
-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

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

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

#To remove debug logs:
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}
Viktor M.
  • 4,393
  • 9
  • 40
  • 71

2 Answers2

5

There are similar problems discussed here in Stackoverflow:

Android Proguard Duplicate Definition

Duplicate resources when using ProGuard and an Android application

Android - Proguard duplicate zip entry error

In Your case, I think the first one could help You...

If this does not help, we should look from where this issue comes. I even have some apps at playstore with third party libs and I had no problems with proguard. Here are my proguard.cfg settings from one of my app with a third party lib and google lvl licensing:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontwarn **CompatHoneycomb
-keep class android.support.v4.** { *; }
-dontwarn org.apache.**
-verbose
-dontoptimize
-dontshrink
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keepattributes *Annotation*
-dontwarn com.google.ads.**

well, You don´t need all them, it depends what you have implemented or which third party libs You use. So, I couldn´t see your app structure and got no code, this would exceed the scope. I suggest that You just test one by one.

Community
  • 1
  • 1
Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
  • I have already tried to fix this problem by these ways and tried it once more but it doesn't help me. I have received thousands notes - duplicate definition of program class + Some errors - " Caused by: java.io.IOException: Duplicate zip entry [jackson-databind-2.1.4.jar:com/fasterxml/jackson/databind/AbstractTypeResolver.class]" in the during of apk building. I use IDEA IDE for android development and apk building and it seems this IDE writes jars automatically then, of course, when I try to add injars too I receive more notes and warnings due to I try to write jars twice. Any more ideas? – Viktor M. May 07 '13 at 14:58
  • I`m pretty sure first way should help me(at least I see it by amount of positive feedbacks of this solution) but it isn`t so in my case, maybe, it is due to IDEA seriously. What do you think and how to change this IDE behaviour? I tried to find something similar on this behaviour in google but no positive results. – Viktor M. May 07 '13 at 15:02
5

The 6 warnings and 3 notes that you currently list are harmless.

You should make sure that you are using a recent version of the Android SDK, which creates an empty proguard-project.txt for your project. The standard Ant build and Eclipse build take care of the important configuration internally (I presume you're using Ant from IDEA). You can still add application-specific options to proguard-project.txt, like the -keep options for Jackson and ActionBarSherlock. Do not add options like -injars/-libraryjars/-outjars, since the build process specifies them for you.

Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • I hope that these warnings and notes are really harmless. In general, the app seems working correctly now in spite of these messages. As for other yours recommendations I have it now the same as you said - last Android SDK, build signed apk from IDEA(didn`t try to run Ant for building from command-line), remove all injars,outjats,libjars due to it causes quite more notes of duplicates, use -keep to wrap unaffected classes – Viktor M. May 09 '13 at 10:51