facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.81k stars 24.29k forks source link

Getting Error while enabling architecture in Android `TurboModules are enabled, but mTurboModuleRegistry hasn't been set.` #43207

Closed athulantony95 closed 7 months ago

athulantony95 commented 7 months ago

Description

Hi team, I tried to enable new architecture in my RN project for android. App is building ,But i am getting this error when the app opens. TurboModules are enabled, but mTurboModuleRegistry hasn't been set.

Steps to reproduce

  1. It just throws the error once i enabled the architecture support from gradle.properties file.

React Native Version

0.72.10

Affected Platforms

Runtime - Android

Areas

Fabric - The New Renderer, TurboModule - The New Native Module System

Output of npx react-native info

npx react-native info
npm WARN ignoring workspace config at /Users/apple/xxx/xxxx/.npmrc
warn Package @sentry/react-native contains invalid configuration: "dependency.platforms.ios.sharedLibraries" is not allowed,"dependency.hooks" is not allowed. Please verify it's properly linked using "react-native config" command and contact the package maintainers about this.
info Fetching system and libraries information...
(node:9369) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
  OS: macOS 13.5
  CPU: (10) arm64 Apple M2 Pro
  Memory: 118.16 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.0
    path: /opt/homebrew/opt/node@18/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.3
    path: /opt/homebrew/opt/node@18/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11076708
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.21
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.10
    wanted: 0.72.10
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: Not found

npm notice
npm notice New minor version of npm available! 10.2.3 -> 10.4.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.4.0
npm notice Run npm install -g npm@10.4.0 to update!
npm notice

Stacktrace or Logs

Exception in native call
                                                                                                    java.lang.RuntimeException: Could not invoke ThreadManager.startThread
                                                                                                        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
                                                                                                        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
                                                                                                        at com.facebook.jni.NativeRunnable.run(Native Method)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                        at android.os.Looper.loop(Looper.java:288)
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
                                                                                                    Caused by: java.lang.reflect.InvocationTargetException
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
                                                                                                        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188) 
                                                                                                        at com.facebook.jni.NativeRunnable.run(Native Method) 
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) 
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201) 
                                                                                                        at android.os.Looper.loop(Looper.java:288) 
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228) 
                                                                                                        at java.lang.Thread.run(Thread.java:1012) 
                                                                                                    Caused by: java.lang.AssertionError: TurboModules are enabled, but mTurboModuleRegistry hasn't been set.
                                                                                                        at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:19)
                                                                                                        at com.facebook.react.bridge.CatalystInstanceImpl.getTurboModuleRegistry(CatalystInstanceImpl.java:474)
                                                                                                        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:485)
                                                                                                        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:469)
                                                                                                        at com.facebook.react.bridge.ReactContext.getNativeModule(ReactContext.java:205)
                                                                                                        at com.reactlibrary.JSThread.runFromContext(JSThread.java:34)
                                                                                                        at com.reactlibrary.RNThreadModule.startThread(RNThreadModule.java:82)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) 
                                                                                                        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188) 
                                                                                                        at com.facebook.jni.NativeRunnable.run(Native Method) 
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) 
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201) 
                                                                                                        at android.os.Looper.loop(Looper.java:288) 
                                                                                                    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)                                                                                                    at java.lang.Thread.run(Thread.java:1012) 

Reproducer

none

Screenshots and Videos

Screenshot 2024-02-27 at 3 25 34 PM
github-actions[bot] commented 7 months ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
cortinico commented 7 months ago

@athulantony95 Could you share your MainApplication.kt and MainActivity.kt? Do you have any other custom native code, specifically code related to initialization of the app?

athulantony95 commented 7 months ago

Hi @cortinico Here is the snippet

MainActivity.java

public class MainActivity extends ReactActivity {

/**

* Returns the name of the main component registered from JavaScript.

* This is used to schedule rendering of the component.

*/

@Override

protected String getMainComponentName() {

return "APPNAME";

}

/**

* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link

* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React

* (aka React 18) with two boolean flags.

*/

@Override

protected ReactActivityDelegate createReactActivityDelegate() {

return new DefaultReactActivityDelegate(

this,

getMainComponentName(),

// If you opted-in for the New Architecture, we enable the Fabric Renderer.

DefaultNewArchitectureEntryPoint.getFabricEnabled());

}

}

MainApplication.java

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost = new DefaultReactNativeHost(this) {

@Override

public boolean getUseDeveloperSupport() {

return BuildConfig.DEBUG;

}

@Override

protected List<ReactPackage> getPackages() {

@SuppressWarnings("UnnecessaryLocalVariable")

List<ReactPackage> packages = new PackageList(this).getPackages();

// Packages that cannot be autolinked yet can be added manually here, for example:

packages.add(new RNThreadPackage(mReactNativeHost, new RNPrinterPackage()));

return packages;

}

@Override

protected String getJSMainModuleName() {

return "index";

}

@Override

protected boolean isNewArchEnabled() {

return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;

}

@Override

protected Boolean isHermesEnabled() {

return BuildConfig.IS_HERMES_ENABLED;

}

};

@Override

public ReactNativeHost getReactNativeHost() {

return mReactNativeHost;

}

@Override

public void onCreate() {

super.onCreate();

SoLoader.init(this, /* native exopackage */ false);

IntercomModule.initialize(this, BuildConfig.INTERCOM_API_KEY, BuildConfig.INTERCOM_APP_ID);

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {

// If you opted-in for the New Architecture, we load the native entry point for this app.

DefaultNewArchitectureEntryPoint.load();

}

ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());

}

}
cortinico commented 7 months ago

@athulantony95 would you be able to share your project somehow?

athulantony95 commented 7 months ago

@cortinico not possible atm. Its a private project. Do you have any guesses or theories on why i am getting this error?

cortinico commented 7 months ago

@cortinico not possible atm. Its a private project. Do you have any guesses or theories on why i am getting this error?

Nope not really. Without a reproducer we can't help further. Are you able to use https://github.com/react-native-community/reproducer-react-native to create a reproduce that would fail in the same way?

athulantony95 commented 7 months ago

Okay. I will try to reproduce in the template you've given. Thanks @cortinico

athulantony95 commented 7 months ago

Hi @cortinico i was able to get rid of the error while i tried to remove the multi-threading package we are using.I believe the maintainers of that library can help me. I will be closing this thread and moving the conversation to respective repo. Thanks again!

cortinico commented 7 months ago

Great thank you very much 👍 Could you link the issue you opened on the other repo?