Skip to content

AGP 9: build fails on getDefaultProguardFile('proguard-android.txt') #459

Description

@docayapay-wq

Bug

Building an app that includes this plugin fails with Android Gradle Plugin 9.0 because android/build.gradle passes proguard-android.txt to getDefaultProguardFile(). AGP 9 rejects that file outright — it contains -dontoptimize, which disables R8 optimizations for the whole build.

* Where:
Build file '.../node_modules/@capacitor-community/admob/android/build.gradle'

* What went wrong:
A problem occurred evaluating project ':capacitor-community-admob'.
> `getDefaultProguardFile('proguard-android.txt')` is no longer supported since it includes
  `-dontoptimize`, which prevents R8 from performing many optimizations. Instead use
  `getDefaultProguardFile('proguard-android-optimize.txt)`, and if needed, temporarily use
  `-dontoptimize` in a custom keep rule file while fixing breakages.

Source

https://github.com/capacitor-community/admob/blob/main/android/build.gradle — the release build type:

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

Suggested fix

Switch to the optimizing variant, which is what AGP recommends and what the app module template has used for years:

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

Since minifyEnabled false is set here, this line has no effect on the library build itself — but it does block consuming apps from configuring AGP 9 at all, because the failure happens during project evaluation.

Why this matters beyond AGP 9

Google Play Console now actively recommends upgrading to AGP 9 under "R8 optimization" in the release dashboard, so apps that depend on this plugin cannot act on that recommendation.

Separately, -dontoptimize is a global R8 directive: if any dependency contributes it through consumer ProGuard rules, optimization is disabled for the entire app and there is no way to re-enable it from the app module. We hit exactly that in this app through a different dependency — Play Console reported "App optimization below our threshold — Optimization 0%" and the AAB's BUNDLE-METADATA/com.android.tools/r8.json showed isOptimizationsEnabled: false. Removing the offending module brought it back to true. Worth avoiding proguard-android.txt for that reason alone.

Environment

@capacitor-community/admob 8.1.0
@capacitor/android 8.5.1
AGP 9.0.0
Gradle 9.1.0
Kotlin Gradle plugin 2.2.20
compileSdk / targetSdk 36

Reproduction

  1. In a Capacitor 8 app with this plugin, set AGP to 9.0.0 and the Gradle wrapper to 9.1.0.
  2. gradle.properties: android.builtInKotlin=false and android.newDsl=false (both currently required — AGP 9's built-in Kotlin support conflicts with kotlin-android, and AGP itself suggests newDsl=false as the temporary workaround).
  3. Run ./gradlew :app:assembleRelease.

Note that compileSdk is already specified in 8.1.0, so the earlier AGP 9 error about a missing compileSdk no longer occurs — this ProGuard line is the remaining blocker.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions