How to enable ProGuard obfuscation in Android Studio?

To enable ProGuard in Android Studio.

Below is the sample how to enable default ProGuard in Android Studio.

  1. Go to the build.gradle file of app
  2. enable the minifyEnabled true
  3. enable shrinkResources true to reduce the APK size
  4. proguardFiles getDefaultProguardFile('proguard-android.txt')
    to enable the default one. If you want to use your own proguard file then use the below rules.

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

The link with ProGuard settings for Android and other settings are available in these links:

For more detail go through this link

Leave a Comment