capacitor-community / capacitor-community/admob
AGP 9: build fails on getDefaultProguardFile('proguard-android.txt')
- Dominant language
- Java
- Stars
- 296
- Forks
- 97
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 7
Description
### 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:
```gradle
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:
```gradle
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.
Contributor guide
Research direction
Start in android/build.gradle at the release build type and inspect the getDefaultProguardFile call that uses proguard-android.txt. Reproduce with AGP 9.0.0 using ./gradlew :app:assembleRelease; done means project evaluation and the release build complete without this ProGuard compatibility failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android
- Domain
- build-system, mobile
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100