Posts proguard
Post
Cancel

proguard

references : http://developer.android.com/tools/help/proguard.html http://proguard.sourceforge.net/ http://sourceforge.net/p/proguard/discussion/182456/thread/e4d73acf/

howto :

At project location always there are two files project.properties and proguard-project.txt.

first enable the proguard (obfuscation take place on  release only, no for debug) via project.properties (unrem proguard.config)

1
2
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

${sdk.dir}/tools/proguard/proguard-android-optimize.txt - proguard is always at androidSDK folder proguard-project.txt - by default look to your android project/proguard-project.txt

setup the proguard-project.txt (only when having problems)

otherwise ${sdk.dir}/tools/proguard/proguard-android-optimize.txt contains the default obfuscation parameters.

most of the time, when using 3rd party jar’s because contain reference to 4th party assemblies we got errors (obfuscation failed) such as cant find a specific classes that we dont even know it… !

warning dont use -injars -outjars -libraryjars swtiches, most of the users suggest to use them, dont use them, there is no need!

we use the -dontwarn switch, example :

js-dontwarn org.apache.** -dontwarn org.shaded.apache.** -dontwarn org.brickred.** -dontwarn com.squareup.okhttp.**

we use -keepnames switch, example :

js-keepnames class com.shaded.fasterxml.jackson.** { *; }

another usual error is that  ’proguard removes annotations’ we use -keepattributes to disable the removal :

js-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault //or if you still have problems use : -keepattributes **

combine with -keep (3rd party jar, performs introspection on parsed classes to find getters and setters) :

js-keep public class com.ourPRJtest.** { public void set*(***); public *** get*(); }

or for a type :

```js-keep class org.shaded.apache.** { *; } -keep interface android.support.v4.app.** { *; } -keep class android.support.v4.** { *; }

1
2
3
4
5
6
7
the events declared to activity xml's can continue work  with <span style="color: #ff0000;">**-keepclassmembers**</span> (already at proguard-android-optimize.txt)  :

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

when having troubles with enums

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

for android.os.Bundle’s obfuscation problems (thanks garymb) :

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

remove all log.* lines from code :

1
-assumenosideeffects class android.util.Log { public * ; }

VA1

1
2
3
4
5
6
7
-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

VA2

1
2
3
4
-dontobfuscate
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers

origin - http://www.pipiscrew.com/?p=821 android-proguard

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags