Fix warning about deprecated Gradle keepRules.file API (#7498)

* Fix warning about deprecated `keepRules.file` API

The proguard files have been moved to `app/proguard` in several directories for `common`, `foss`, and `enterprise` rules and it's those directories that are added through `keepRules.addStaticSourceDirectory(dir)`.

* Use `findPropery` instead of the deprecated `project.properties["key"]` API for `allWarningsAsErrors`

* Remove very legacy .gitignore rule and restore proguard `.keep` rules
This commit is contained in:
Jorge Martin Espinosa
2026-08-21 15:23:34 +02:00
committed by GitHub
parent 1300112edc
commit feef42db5a
5 changed files with 29 additions and 21 deletions
-3
View File
@@ -31,9 +31,6 @@ __pycache__/
# Local configuration file (sdk path, etc) # Local configuration file (sdk path, etc)
local.properties local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files # Log Files
*.log *.log
+28 -17
View File
@@ -127,24 +127,11 @@ android {
optimization { optimization {
enable = true enable = true
keepRules { keepRules {
files.add(File(projectDir, "common-proguard-rules.pro")) // Equivalent of adding `getDefaultProguardFile("proguard-android-optimize.txt")` (this is the default value).
files.add(getDefaultProguardFile("proguard-android-optimize.txt")) includeDefault = true
// Depending on whether the app flavor is enterprise or not we want to use different proguard rules.
val flavorProguardFile = if (isEnterpriseBuild) {
// Custom rules for enterprise builds
File(projectDir, "enterprise-proguard-rules.pro")
} else {
// These default rules prevent the OSS app from being obfuscated
File(projectDir, "default-proguard-rules.pro")
}
if (flavorProguardFile.exists()) {
files.add(flavorProguardFile)
} else {
logger.warn("Proguard file ${flavorProguardFile.absolutePath} does not exist")
}
} }
// Our custom keep rules are registered as `keepRules` source folders in the `androidComponents` block below,
// as the former `keepRules.files` DSL is deprecated since AGP 9.
} }
} }
@@ -229,6 +216,30 @@ androidComponents {
) )
onVariants { variant -> onVariants { variant ->
// Register the R8 keep rules source folders for optimized build types (release, nightly).
// Replaces the deprecated `optimization.keepRules.files` DSL (AGP 9+).
if (variant.buildType != "debug") {
variant.sources.keepRules?.let { keepRules ->
// Common rules, always applied.
keepRules.addStaticSourceDirectory("proguard/common")
// Depending on whether the app flavor is enterprise or not we want to use different proguard rules.
val flavorProguardDir = if (isEnterpriseBuild) {
// Custom rules for enterprise builds
"../enterprise/proguard"
} else {
// Custom fules for FOSS builds
"proguard/foss"
}
if (File(projectDir, flavorProguardDir).exists()) {
keepRules.addStaticSourceDirectory(flavorProguardDir)
} else {
logger.warn("Proguard folder ${File(projectDir, flavorProguardDir).absolutePath} does not exist")
}
}
}
// Assigns a different version code for each output APK // Assigns a different version code for each output APK
// other than the universal APK. // other than the universal APK.
variant.outputs.forEach { output -> variant.outputs.forEach { output ->
+1 -1
View File
@@ -98,7 +98,7 @@ allprojects {
// This is disabled by default, but the CI will enforce this. // This is disabled by default, but the CI will enforce this.
// You can override by passing `-PallWarningsAsErrors=true` in the command line // You can override by passing `-PallWarningsAsErrors=true` in the command line
// Or add a line with "allWarningsAsErrors=true" in your ~/.gradle/gradle.properties file // Or add a line with "allWarningsAsErrors=true" in your ~/.gradle/gradle.properties file
allWarningsAsErrors = project.properties["allWarningsAsErrors"] == "true" allWarningsAsErrors = findProperty("allWarningsAsErrors") == "true"
// Uncomment to suppress Compose Kotlin compiler compatibility warning // Uncomment to suppress Compose Kotlin compiler compatibility warning
// freeCompilerArgs.addAll(listOf("-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true")) // freeCompilerArgs.addAll(listOf("-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"))