I want to use Proguard to obfuscate an app’s code. I don’t need optimisations, and I don’t need Proguard to strip any classes or methods out. All I want is obfuscation. The app uses several library projects.
I’ve been banging my head against the wall trying to make it happen and it’s not working the way I want. I am seeing NoSuchMethodExceptions thrown in the app when executed, even though I thought I had turned off Proguard’s shrinking options.
What are the magic settings to have Proguard JUST obfuscate, and not optimise away ANY code?
UPDATE. I’ve confirmed through trial and error that it is the obfuscation process (not the optimisation or shrinking) that is causing the NoSuchMethodExceptions.
Proguard.cfg
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-dontshrink
-keep public class * extends Object
-keep class com.myapp.** { *; }
-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 com.myapp.activity.Splash
-keep public class com.myapp.alarm.AlarmsViewer
-keep public class com.myapp.activity.About
-keep public class com.myapp.activity.Base
-keep public class com.myapp.activity.BaseWithMenu
-keep public class com.myapp.alarm.Alarm
-keep public class com.myapp.alarm.AlarmFragment
-keep public class com.myapp.alarm.AlarmPagerAdapter
-keep public class com.myapp.alarm.AlarmStore
-keep public class com.myapp.app.App
-keep public class com.myapp.preferences.Preferences
-keep public class com.myapp.preferences.PreferencesStore
-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 class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keepattributes *Annotation*
-keep public interface com.android.vending.licensing.ILicensingService
-dontwarn android.support.**
I had similar problems a while back and solved it for me by brute force and luck. My proguard.cfg is similar but I have the lines:
I can’t remember from where I got the idea for these optimization options, but they seem to work for me.
There is always the catch all switch
(Specifies not to optimize the input class files. By default, optimization is enabled; all methods are optimized at a bytecode level.)
which might be more appropriate.
Finally I have methods which are only referenced in xml files (click handlers) which needed to be explicitly kept with