Android: setting up Proguard

I am trying to configure proguard and ran into some problems that are sorted by priority:

  • I got warnings about zip duplication and can't fix this. I use external libraries in the "libs" directory and 2 library projects (one library project has one external lib - added to the project only once), which are added to the project only once. I tried to move my external banks to another directory, that is, "lib" - just rename it because some users managed to solve it, but that does not help me. Another way is to implement custom_rules in basic build.xml, so some users can avoid this warning. But all that does not help from me, how can I fix it? Journal:

    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]) 
  • The last thing is some notes during the signed building apk:

     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 Protection 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(...); } 
+4
source share
2 answers

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

You must make sure that you use the latest version of the Android SDK, which creates an empty proguard-project.txt project for your project. The standard build of Ant build and Eclipse takes care of the important configuration inside (I assume you are using Ant from IDEA). You can add custom options for proguard-project.txt, such as the -keep options for Jackson and ActionBarSherlock. Do not add options such as -injars / -libraryjars / -outjars, as the build process points them out to you.

+5
source

Similar issues are discussed here at Stackoverflow:

Duplicate definition of Android Proguard

Duplicate resources when using ProGuard and Android app

Android - Proguard zip protection re-write error

In your case, I think the first one can help you ...

If this does not help, we must see where this problem comes from. I even have some applications in the playstore with third-party libraries, and I had no problems with proguard. Here are my proguard.cfg settings from one of my third party lib and google lvl licensed applications:

 -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 of them, it depends on what you have implemented or which third-party libraries you use. Thus, I could not see your application structure and did not receive any code, this exceeded the amount. I suggest you just check one by one.

+5
source

Source: https://habr.com/ru/post/1479539/


All Articles