Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Configure Proguard

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(...);
}
like image 399
Viktor M. Avatar asked Dec 26 '22 04:12

Viktor M.


1 Answers

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.

like image 169
Eric Lafortune Avatar answered Jan 06 '23 12:01

Eric Lafortune