Android ProGuard - Obfuscating and Shrinking your code Enable ProGuard for your build

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

For enabling ProGuard configurations for your application you need to enable it in your module level gradle file. you need to set the value of minifyEnabled true.

You can also enable shrinkResources true which will remove resources that ProGuard flaggs as unused.

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

The above code will apply your ProGuard configurations contained in proguard-rules.pro ("proguard-project.txt" in Eclipse) to your released apk.

To enable you to later determine the line on which an exception occurred in a stack trace, "proguard-rules.pro" should contain following lines:

-renamesourcefileattribute SourceFile    
-keepattributes SourceFile,LineNumberTable

To enable Proguard in Eclipse add proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt to "project.properties"



Got any Android Question?