From a629ac4206409442291967bbd87aefcd2e6cf6a6 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 14 Sep 2023 11:13:16 -0700 Subject: [PATCH] Annotate HybridData with DoNotStrip (#39342) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39342 Annotate HybridData with DoNotStrip The stack of diffs aims to introduce new features and deprecate old ones in the React Native Android architecture. The main goal is to make the architecture more stable and easier to use for developers. The changes include marking ReactPackage as NullSafe, introducing the new getModule method, introducing the WillBeDeprecatedInNewArchitecture annotation, deprecating createNativeModules and marking getModule as UnstableReactNativeAPI, and fixing a lint warning in MainReactPackage. # This diff This diff is adding the annotation `DoNotStrip` to the `HybridData` field in the `NativeMethodCallInvokerHolderImpl` and `CallInvokerHolderImpl` classes. This is to prevent the Android ProGuard optimizer from stripping the `HybridData` field, which is necessary for the proper functioning of the TurboModule system in React Native. Additionally, the `BUCK` file for the `core` module is updated to include the `androidx:annotation` and `com.facebook.proguard.annotations:annotations` dependencies. changelog: [intenral] internal# Context Reviewed By: cortinico Differential Revision: D49077065 fbshipit-source-id: cb36c0a11bdb8f5f0f4eaa7db1f0c9dcb3be2341 --- .../react/turbomodule/core/CallInvokerHolderImpl.java | 4 +++- .../turbomodule/core/NativeMethodCallInvokerHolderImpl.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.java index e59bc786e46..d1dd5f77261 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.java @@ -8,6 +8,7 @@ package com.facebook.react.turbomodule.core; import com.facebook.jni.HybridData; +import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; /** @@ -16,7 +17,8 @@ import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; * pass it from CatalystInstance, through Java, to TurboModuleManager::initHybrid. */ public class CallInvokerHolderImpl implements CallInvokerHolder { - private final HybridData mHybridData; + + @DoNotStrip private final HybridData mHybridData; static { NativeModuleSoLoader.maybeLoadSoLibrary(); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/NativeMethodCallInvokerHolderImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/NativeMethodCallInvokerHolderImpl.java index 1f7012bdfb7..4a0cbcc5a12 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/NativeMethodCallInvokerHolderImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/NativeMethodCallInvokerHolderImpl.java @@ -8,6 +8,7 @@ package com.facebook.react.turbomodule.core; import com.facebook.jni.HybridData; +import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHolder; /** @@ -18,7 +19,7 @@ import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHol */ public class NativeMethodCallInvokerHolderImpl implements NativeMethodCallInvokerHolder { - private final HybridData mHybridData; + @DoNotStrip private final HybridData mHybridData; static { NativeModuleSoLoader.maybeLoadSoLibrary();