Skip to content

bug: Build failure on AGP 9.0+ due to unsupported 'proguard-android.txt' #193

Description

@tiennp-dev

Description:

Info:

• Plugin Version: 8.1.0
• Android Gradle Plugin (AGP) Version: 9.2.1

Describe the Bug

When building an Android project using Android Gradle Plugin 9.x, the build fails with an exception
evaluating :capacitor-community-fcm because of a call to getDefaultProguardFile('proguard-android.txt') .

Modern versions of AGP and the R8 compiler no longer support proguard-android.txt because it includes the -
dontoptimize flag, which prevents optimization. Instead, AGP requires libraries to use proguard-android-optimize.txt

Steps to Reproduce

  1. Configure an Android project with AGP 9.x .
  2. Add @capacitor-community/fcm .
  3. Run gradlew assembleDebug or gradlew assembleRelease .

Error Log / Stack Trace

* Where:                                                                                                            
Build file 'node_modules/@capacitor-community/fcm/android/build.gradle' line: 34                                    
                                                                                                                    
* What went wrong:                                                                                                  
A problem occurred evaluating project ':capacitor-community-fcm'.                                                   
> `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.                     

Suggested Fix

Update the proguardFiles configuration in the plugin's android/build.gradle file to use proguard-android-
optimize.txt instead:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions