Thursday 25 December 2014

How to Proguard Android APK

How to Proguard Android APK


-in jars: Specifies the input jars (or aars, wars, ears, zips, apks, or directories) of the application to be processed

-outjars:Specifies the names of the output jars (or aars, wars, ears, zips, apks, or directories). The processed input of the preceding -injars options will be written to the named jars.

-libraryjars: Specifies the library jars (or aars, wars, ears, zips, apks, or directories) of the application to be processed. The files in these jars will not be included in the output jars.

-dontskipnonpubliclibraryclassmembers: Specifies not to ignore package visible library class members (fields and methods).

-keep: Specifies classes and class members (fields and methods) to be preserved as entry points to your code.

Here  ReportingInteractionMode is a class in ACRA library. we have to keep this library in src to suppress Crash No such filed TOAST.
-keep class org.acra.ReportingInteractionMode { *; }  

Copy this contain and create file proguard.cfg and past into it.

 -injars   bin/classes  
 -injars   libs  
 -outjars   bin/classes-processed.jar  
 -libraryjars /home/.../adt-bundle-linux-x86-20140321/sdk/platforms/android-19/android.jar  
 -libraryjars /home/.../libs/android-query-full.0.26.7.jar  
 -libraryjars /home/.../libs/javassist.jar  
 -libraryjars /home/.../libs/joda-time-2.3.jar  
 -libraryjars /home/.../libs/libphonenumber-5.9.jar  
 -libraryjars /home/.../libs/nineoldandroids-2.4.0.jar  
 -optimizationpasses 1  
 -dontpreverify  
 -dontskipnonpubliclibraryclassmembers  
 -repackageclasses ''  
 -allowaccessmodification  
 -optimizations !code/simplification/arithmetic,!field  
 -keepattributes *Annotation*       
 -dontusemixedcaseclassnames  
 -dontskipnonpubliclibraryclasses  
 -dontpreverify  
 -verbose  
 -allowaccessmodification  
 -keepattributes *Annotation*  
 -dontwarn android.support.v7.**  
 -dontwarn in.android.Databases.**  
 -dontwarn in.android.PushNotification.**  
 -dontwarn in.andoroid.Utills.FileUtill  
 -dontwarn android.support.v4.**  
 -dontwarn com.androidquery.auth.**  
 -dontwarn javassist.**  
 -dontwarn org.brickred.socialauth.**  
 -dontwarn org.joda.time.**  
 -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.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 *;  
 }  
 # for minmize ACRA library Error we are using this ReportingInteractionMode   
 # otherwise you will get No Such field Toast   
 -keep class org.acra.ReportingInteractionMode { *; }  

In project.properties add this attribute and save it.

proguard.config=proguard.cfg 

then, export the project and create new keystore if you haven't created or use existing keystore and finish the wizard.

No comments:

Post a Comment

Things after Kotlin Android Extensions

Things after Kotlin Android Extensions(KTX) I remembered in MVVM when I have to declare ViewModel, I initialize View Model like this. p...