Skip to content

Android: replace android.r8.strictFullModeForKeepRules=false with explicit keep rules before AGP 11 #4783

Open

Description

@kaloudis

#4566 (React Native 0.87.1, AGP 9.2.1) sets android.r8.strictFullModeForKeepRules=false in android/gradle.properties (6efe9af). Without it, R8 removes no-arg constructors that libraries create through reflection, and release builds crash on launch (WorkDatabase_Impl) or the QR scanner fails to start (ML Kit registrars).

AGP 9 defaults this option to true, deprecates it in AGP 10 and removes it in AGP 11. Before we move to AGP 11, the flag needs to be replaced with explicit rules in android/app/proguard-rules.pro.

Consumer rules known to rely on the old behavior (a -keep class rule with no member list):

  • room-runtime 2.5.0: -keep class * extends androidx.room.RoomDatabase
  • firebase-components 16.1.0 / 17.1.0: -keep class * implements com.google.firebase.components.ComponentRegistrar (ML Kit BarcodeRegistrar, CommonComponentRegistrar, VisionCommonRegistrar)
  • work-runtime 2.8.1: -keep class * extends androidx.work.InputMerger

Likely replacements:

-keep class * extends androidx.room.RoomDatabase { <init>(); }
-keep class * implements com.google.firebase.components.ComponentRegistrar { <init>(); }
-keep class * extends androidx.work.InputMerger { <init>(); }

This list may be incomplete. To find the rest, run ./gradlew :app:minifyReleaseWithR8 with the flag removed and diff app/build/outputs/mapping/release/usage.txt against a build with the flag set. Any <init>() that only appears in the strict build needs a rule. Bumping these libraries may also fix some of them upstream, since newer releases ship explicit <init>() rules.

Testing: a signed release build must launch and open the QR scanner, and a WorkManager job must run.

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

    AGPAndroid AGP (Android Gradle Plugin)AndroidAndroid issuesBuild process

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions