cli icon indicating copy to clipboard operation
cli copied to clipboard

Need Help with Enabling New architecture in brownfield React Native with android multi module app

Open sanjeevyadavIT opened this issue 10 months ago • 4 comments

Description

I have a brownfield React Native setup where I have enabled New Architecture and am now trying to write a Turbo Native Module as per the official documentation. However, I am encountering the following error when launching the React Fragment:

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'NativeLocalStorage' could not be found. 
Verify that a module by this name is registered in the native binary.

Project Structure

I have a multi-module Android project structured as follows:

react-native-brownfield-example/
│── app/                 # Native Android app module
│   ├── MainApplication.kt
│   ├── MainActivity.kt
│   ├── build.gradle.kts
│
│── feature/             # Modularized feature components
│   ├── react/           # Contains all React integration code
│   │   ├── NativeLocalStorageModule.kt
│   │   ├── ReactNativeHost
│   │   ├── build.gradle.kts
│
│── reactNative/         # React Native project
│   ├── specs/NativeLocalStorage.ts
│   ├── index.android.js
│   ├── package.json

Reproducible Example

A minimal, reproducible example is available in this repository:

🔗 GitHub Repo

Steps to Reproduce

  1. Clone the repository:
git clone https://github.com/sanjeevyadavIT/react-native-brownfield-example.git
cd react-native-brownfield-example
git checkout feat/add-native-module
  1. Install dependencies:
cd reactNative
npm install
cd ..
  1. Generate codegen artifacts:
./gradlew generateCodegenArtifactsFromSchema
  1. Open the project in Android Studio and run the app. Image

  2. Click "Open React Fragment" in the UI. Image

  3. Observe the Invariant Violation error.

Solution provided by Facebook team @cortinico

I raised this same issue https://github.com/facebook/react-native/issues/49246 and @cortinico provided the solution here -> https://github.com/facebook/react-native/issues/49246#issuecomment-2643110585

But the problem with the solution provided by Nicola Corti is (although it works) it adds a @private/react-native-feature in node_modules and move all the Android integration code written in feature/react into $rootProject/reactNative/@node_modules/@private/react-native-feature but my Actual project has tons of feature module which depends on feature/react module and some of the class are auto generated using dependency injection that relies on code written in feature/react, using this solution doesn't work

Help Needed

✅ Is there any changes needed in my brownfield setup for android multi-module project? ✅ How can I correctly register my Turbo Native Module within a multi-module Android project?

sanjeevyadavIT avatar Feb 11 '25 12:02 sanjeevyadavIT

@michalchudziak can you please help me or point to someone who can help me

sanjeevyadavIT avatar Feb 12 '25 03:02 sanjeevyadavIT

@sanjeevyadavIT did you solve it? react native doc turbo module example is not working

bumjin1013 avatar Mar 26 '25 06:03 bumjin1013

@sanjeevyadavIT I'm not able to see your reproducible github link. Could you make sure it's public? Seems like the turbo modules don't get linked properly. I'd try linking them manually and see if it helps.

atlj avatar Mar 26 '25 09:03 atlj

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

github-actions[bot] avatar Jun 25 '25 03:06 github-actions[bot]