diff --git a/packages/react-native/ReactAndroid/proguard-rules.pro b/packages/react-native/ReactAndroid/proguard-rules.pro index 7e6c92af074a..0db726d9a2af 100644 --- a/packages/react-native/ReactAndroid/proguard-rules.pro +++ b/packages/react-native/ReactAndroid/proguard-rules.pro @@ -73,3 +73,7 @@ -keep public class com.facebook.imageutils.** { public *; } + +# Activity result launcher keys include the contract's class name. Keep those names so that R8 +# doesn't merge different contracts into one class or rename them between builds. +-keepnames class * extends androidx.activity.result.contract.ActivityResultContract diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/activityresult/__docs__/README.md b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/activityresult/__docs__/README.md index bdc6c9bdf046..1542339a6071 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/activityresult/__docs__/README.md +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/activityresult/__docs__/README.md @@ -61,7 +61,10 @@ The same stability concern applies to minification. If the app minifies class names (R8/ProGuard), the obfuscated name of the owner class is not guaranteed to be the same from one build to the next, so a result delivered after an app update can be dropped. Keep the owner class's name (for example with -`-keepnames`) if results must survive across builds. +`-keepnames`) if results must survive across builds. React Native's consumer R8 +rules already keep the names of `ActivityResultContract` subclasses, so R8 +doesn't merge different contracts into one class, which would give them the same +key. Registering the same contract class twice from one owner throws `IllegalStateException`. In that case use the overload that takes a key: