Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard Android App for LVL and Fragment Compatibility Support

I'm trying to use Proguard against my app which will eventually incorporate LVL and In-app Billing. The problem I have is that Proguard keeps crashing my app on start and it's hard to figure out what's failing.

I'm using the Android V4 support compatibility library and it seems to be blowing away that library as well as some other stuff.

Does anyone has a proguard.cfg that works with a basic version of the v4 compat library for starters?

Currently I'm using the stock proguard.cfg which doesn't work.

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

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

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
like image 842
Jeremy Edwards Avatar asked May 22 '11 20:05

Jeremy Edwards


2 Answers

That's not enough to produce a working application.. proguard will for example delete all your fragments by default, and there are some more compat. libraries it uses.

I've found the following works:

-dontwarn **CompatHoneycomb
-dontwarn **CompatHoneycombMR2
-dontwarn **CompatCreatorHoneycombMR2
-keep class android.support.v4.** { *; }

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

In theory if you simply want proguard as an obfuscator and are not ineterested in its other 'features', then

-dontshrink
-dontoptimize

Should switch it off. Even with that, though test thoroughly on a real android 1.6 phone. I didn't and found too late proguard had made a breaking change to the binary that only manifested on 1.6...

like image 95
user848959 Avatar answered Sep 21 '22 09:09

user848959


To have Proguard working with v4 compatibility library add this to your proguard.cfg:

-dontwarn **CompatHoneycomb
-keep class android.support.v4.** { *; }
like image 28
Adep Software Avatar answered Sep 21 '22 09:09

Adep Software