androidproguard

Runtime issues while using Proguard to minify


My app is completely ready to deploy and its using many libraries. I want to minify the code using Proguard and also want to remove unused classes and resources but while using proguard I am getting Runtime error

java.lang.RuntimeException: Unable to create application com.rig.onblick.App: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference

I gone through many tutorial but its seems too complicated to write proguard configuration because I have to write many rules to make sure my app will run perfectly. I have never used proguard in this kind of big project. Can anyone tell me the minimal configuration which make sure at least my code will be minified and will not get any runtime error.

My present configuration is as below.

-dontwarn com.witt.mspapp.**

-keep class com.github.mikephil.** { *; }
-dontwarn com.github.mikephil.**

-keep class com.github.mikephil.** { *; }
-dontwarn org.apache.**

-keep class com.google.gms.** { *; }
-dontwarn com.google.gms.**

-keep class com.viewpagerindicator.** { *; }
-dontwarn com.viewpagerindicator.**

-keep class org.jivesoftware.smackx.** { *; }
-dontwarn org.jivesoftware.smackx.**

I am testing in debug env. and my gradle configuration is as below

debug {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

Solution

  • There is no "minimal configuration" for proguard. You will get the proguard configuration for each library from their official repo. So, go through these configurations for each dependency you use and add them to your proguard rules.