New ProGuard Gradle Plugin Beta for Android!

With the upcoming release of AGP 7.0 and its switch to using R8 as the in-built shrinker, we are about to make it seamless to continuing using the time-tested ProGuard with your Android project. ProGuard 7.1 will ship with an updated Gradle Plugin that is compatible with AGP 7 allowing you to continue using ProGuard with your Android project.

Before we release the new ProGuard Gradle Plugin we would like to do some testing and would appreciate your input.

ProGuard Gradle Plugin Beta is available via Maven Central (mavenCentral()) with artifact ID com.guardsquare:proguard-gradle:7.1.0-beta5

Here are some instructions of how to upgrade:

  1. Remove the enableR8 property from your gradle.properties properties file, since this is now deprecated.

android.enableR8=false
android.enableR8.libraries=false

  1. Remove the dependency substitution which substituted the built-in ProGuard with the latest ProGuard version.
buildscript {
    ...
    configurations.all {
        resolutionStrategy {
            dependencySubstitution {
                substitute module('net.sf.proguard:proguard-gradle') with module('com.guardsquare:proguard-gradle:7.0.1')
            }
        }
    }
}
  1. Add a classpath dependency on the latest ProGuard Gradle plugin.
buildscript {
    repositories {
        google()       // For the Android Gradle plugin.
        mavenCentral() // For the ProGuard Gradle Plugin and anything else.
    }
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-beta03'  // The Android Gradle plugin.
        classpath 'com.guardsquare:proguard-gradle:7.1.0-beta5'  // The ProGuard Gradle plugin.
    }
}
  1. Apply the ProGuard plugin in your app module `build.gradle(.kts).
apply plugin: 'com.android.application'
apply plugin: 'proguard'
  1. Remove ProGuard configuration from the buildTypes and disable built-in minification.
android {
    ...
    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFile getDefaultProguardFile('proguard-android.txt')
            proguardFile 'proguard-project.txt'
        }
    }
}

You should remove the proguardFile configurations and set minifyEnabled and shrinkResources to false .

apply plugin: 'com.android.application'

android {
    ...
    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
        }
        release {
            minifyEnabled false
            shrinkResources false
        }
    }
}
  1. Add your ProGuard configuration to the new proguard block.
android {
    ...
}

proguard {
   configurations {
      release {
         defaultConfiguration 'proguard-android-optimize.txt'
         configuration 'proguard-project.txt'
      }
   }
}
  1. You can then build your application as usual and ProGuard will be automatically executed on the configured variants as before.
./gradlew assembleRelease

Any thoughts, let us know here. If you have any bugs or issues to report, please do so on Github.