Home > Mobile >  Android Gradle Plugin 7.2 ignores added proguard file in Android App build process
Android Gradle Plugin 7.2 ignores added proguard file in Android App build process

Time:05-31

I have a Gradle plugin I wrote for an Android app project. Amongst other things - this plugin adds a custom ProGuard rules file to all ApplicationVariants being built.

the has worked fine until Android Gradle plugin 7.2 was introduced. Since I started using AGP 7.2 to compile my app - the ProGuard file that's added by the plugin is ignored.

Code:

    project.android.buildTypes[<variant.buildType.name>].proguardFile = new File(<custom Proguard rules file path>)

This worked in AGP <= 7.0 without any problems. There are no exceptions in the logs of the build process.

I tried another approach and got the same results : I tried to add a ProGuard file with a script (not using a plugin at all) - but the results were the same - this file is ignored. This is the code I added in build.gradle :

afterEvaluate {
    for (def buildType : project.android.buildTypes) {
       buildType.proguardFile file(< full path>)
    }
}

Any ideas? Thanks!

CodePudding user response:

In Groovy the value can be set for android.defaultConfig:

// this sets one file
android.defaultConfig { config ->
    proguardFile new File("../general.pro")
}

// this adds an additional file
android.defaultConfig { config ->
    proguardFiles.add(new File("../general.pro"))
}

// proof of concept
android.buildTypes { buildType ->
    println buildType
}

This happens before :prepareKotlinBuildScriptModel, which means early on.

  • Related