ProguardGui make my android jar miss many classes

216 views Asked by At

I wanna use Proguard to obfuscates my Android jar which has nearly 3000 classes, however, when I use Proguard to obfuscates it, I found the output jar is only has 1 class ! Who can help me I will appreciate! I post the configuration and the output log below

Proguard configuration

 -injars 'E:\Users\DalenRuan\workspace\Predictor_lib\predictor_lib.jar'
-outjars 'E:\Users\DalenRuan\workspace\Predictor_lib\out_predictor_lib.jar'

-libraryjars 'E:\adt-bundle-windows-x86-20140702\sdk\platforms\android-18\android.jar'
-libraryjars 'E:\Users\DalenRuan\workspace\Predictor_lib\libs\httpmime-4.1.1.jar'

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

-keep public class * extends android.app.Activity

-keep public class * extends android.app.Application

-keep public class * extends android.app.Service

-keep public final class *

output log

Reading input...
Reading program jar [E:\Users\DalenRuan\workspace\Predictor_lib\predictor_lib.jar]
Reading library jar [E:\adt-bundle-windows-x86-20140702\sdk\platforms\android-18\android.jar]
Reading library jar [E:\Users\DalenRuan\workspace\Predictor_lib\libs\httpmime-4.1.1.jar]
Initializing...
Note: the configuration refers to the unknown class 'our.company.project.ProjectAPI'
Note: the configuration refers to the unknown class 'our.company.project.ProjectAPI'
Note: there were 2 references to unknown classes.
      You should check your configuration for typos.
Ignoring unused library classes...
  Original number of library classes: 3305
  Final number of library classes:    411
Shrinking...
Removing unused program classes and class elements...
  Original number of program classes: 241
  Final number of program classes:    1
Inlining subroutines...
Optimizing...
  Number of finalized classes:                 0
  Number of vertically merged classes:         0   (disabled)
  Number of horizontally merged classes:       0   (disabled)
  Number of removed write-only fields:         0   (disabled)
  Number of privatized fields:                 0   (disabled)
  Number of inlined constant fields:           0   (disabled)
  Number of privatized methods:                0
  Number of staticized methods:                0
  Number of finalized methods:                 0
  Number of removed method parameters:         0
  Number of inlined constant parameters:       0
  Number of inlined constant return values:    0
  Number of inlined short method calls:        0
  Number of inlined unique method calls:       0
  Number of inlined tail recursion calls:      0
  Number of merged code blocks:                0
  Number of variable peephole optimizations:   0
  Number of arithmetic peephole optimizations: 0   (disabled)
  Number of cast peephole optimizations:       0
  Number of field peephole optimizations:      0
  Number of branch peephole optimizations:     0
  Number of string peephole optimizations:     0
  Number of simplified instructions:           0
  Number of removed instructions:              0
  Number of removed local variables:           0
  Number of removed exception blocks:          0
  Number of optimized local variable frames:   0
Obfuscating...
Preverifying...
Writing output...
Preparing output jar [E:\Users\DalenRuan\workspace\Predictor_lib\out_predictor_lib.jar]
  Copying resources from program jar [E:\Users\DalenRuan\workspace\Predictor_lib\predictor_lib.jar]
Processing completed successfully
1

There are 1 answers

0
kaushal On

You should search for proguard configuration for each API and jars you have declared in dependencies of your build.gradle file.for eg if you are using fabric api you can get proguard codes from its documentation here https://docs.fabric.io/android/crashlytics/dex-and-proguard.html or if you are using volley in your code then you must write -keep class com.android.volley.** { *; } and so on, Don't use -ignorewarnings in begining try suppressing warnings using -dontwarn for the corresponding errors for the dependencies and most importantly include all your java classes in following ways

##Keep classes that are referenced on the AndroidManifest
-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.preference.Preference

-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.preference.Preference

#
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}
#
##support libs(cab be used more wisely)
-keep class android.support.v4.** { *; }
-keep class android.support.v7.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.support.v7.**

    ##Fragments
-keep public class * extends android.app.Fragment

    -keep class com.your-packagename.**{ *; }

Lastly you can also use -dontnote to remove the messages like duplicate jars etc eg:-dontnote org.apache.http.** Lastly refer the documentation here https://www.guardsquare.com/en/proguard/manual/examples https://www.guardsquare.com/en/proguard/manual/troubleshooting Thanks