Skip to content

Commit c7d73bb

Browse files
authored
Keep UIManagerHelper.getUIManager and UIManager.resolveView in ProGuard rules (#59892)
Summary: Tools that inspect an app's views from outside the app's own code, such as OS-level accessibility and UI-understanding services, can identify the views React Native rendered by asking React Native itself. `UIManagerHelper.getUIManager()` returns the `UIManager` for a view's React context. `UIManager.resolveView(reactTag)` then returns the view React Native mounted under that tag, and the tool compares it with the view it has. In R8-minified release builds, that path isn't reliably available: - `UIManagerHelper` is outside the `com.facebook.react.bridge` package that the shipped consumer rules keep, so R8 renames it or removes it entirely. The only path left is `ReactContext.getFabricUIManager()`, which is deprecated in favor of `UIManagerHelper.getUIManager()`. - Builds that use `reactnative.pro` instead of the shipped consumer rules don't keep the `bridge` package, and R8 removes `resolveView` from `FabricUIManager`. This change adds the same rules to the shipped consumer rules (`proguard-rules.pro`) and to `reactnative.pro`: - Keep `UIManagerHelper.getUIManager`. - Keep `UIManager.resolveView(int)` on the interface. Because the interface method keeps its name, R8 keeps `resolveView` under that name on the implementations in use, such as `FabricUIManager`. The shipped rules already keep it through the `bridge` rule. Naming it explicitly keeps it if that rule is ever narrowed. The rules don't keep class names such as `ReactRootView` or `ReactViewGroup`. A tool can cache the classes that `resolveView` confirms and skip the lookup for later views of the same class. It can recognize React Native's context through `getUIManager`'s parameter type, even when `ReactContext` is renamed. Changelog: [Android][Changed] - Keep `UIManagerHelper.getUIManager` and `UIManager.resolveView` in the ProGuard rules, so tools can identify React Native views in minified apps Reviewed By: javache Differential Revision: D129915044 Pull Request resolved: #59892
1 parent 546c71c commit c7d73bb

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎packages/react-native/ReactAndroid/proguard-rules.pro‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@
5151
-keep,includedescriptorclasses class com.facebook.react.turbomodule.core.** { *; }
5252
-keep,includedescriptorclasses class com.facebook.react.internal.turbomodule.core.** { *; }
5353

54+
# Let tools outside the app's own code, such as OS accessibility and UI-understanding
55+
# services, identify the views React Native renders: UIManagerHelper returns the
56+
# UIManager for a view's React context, and UIManager.resolveView(reactTag) returns the
57+
# view React Native mounted under that tag.
58+
-keep class com.facebook.react.uimanager.UIManagerHelper {
59+
public static *** getUIManager(...);
60+
}
61+
-keep interface com.facebook.react.bridge.UIManager {
62+
android.view.View resolveView(int);
63+
}
64+
5465
# hermes
5566
-keep class com.facebook.jni.** { *; }
5667

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/reactnative.pro‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818
-keep class **$$ReactModuleInfoProvider
1919
-keep class com.facebook.react.bridge.ReadableType { *; }
2020

21+
# Let tools outside the app's own code identify the views React Native renders.
22+
# Keep in sync with ReactAndroid/proguard-rules.pro, which explains each rule.
23+
-keep class com.facebook.react.uimanager.UIManagerHelper {
24+
public static *** getUIManager(...);
25+
}
26+
-keep interface com.facebook.react.bridge.UIManager {
27+
android.view.View resolveView(int);
28+
}
29+
2130
-keepnames class com.facebook.quicklog.QuickPerformanceLogger {
2231
void markerAnnotate(int,int,java.lang.String,java.lang.String);
2332
void markerTag(int,int,java.lang.String);

0 commit comments

Comments
 (0)