Content-Length: 290911 | pFad | http://github.com/facebook/react-native/issues/48622

8F java.lang.AssertionError: TurboModules are enabled, but mTurboModuleRegistry hasn't been set. · Issue #48622 · facebook/react-native · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.AssertionError: TurboModules are enabled, but mTurboModuleRegistry hasn't been set. #48622

Open
HeLiHuang opened this issue Jan 12, 2025 · 5 comments
Labels
Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@HeLiHuang
Copy link

HeLiHuang commented Jan 12, 2025

Description

MainApplication.kotlin:

class MainApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    SoLoader.init(this, OpenSourceMergedSoMapping)
    if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
      // If you opted-in for the New Architecture, we load the native entry point for this app.
      load()
    }
  }
}

RNViewHostActivity.Java:

public class RNBaseActivity extends Activity implements DefaultHardwareBackBtnHandler {
    private static final String TAG = "RNBaseActivity";
    private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setCurrentActivity(this)
                .setBundleAssetName("index.android.bundle")
                .setJSMainModulePath("index")
                .addPackage(new MainReactPackage())
                .addPackage(new MyPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();


        mReactRootView = new ReactRootView(this);
        mReactRootView.startReactApplication(mReactInstanceManager, "IotReactNativeApp", null);
        setContentView(mReactRootView);
    }


    @Override
    protected void onPause() {
        super.onPause();
        mReactInstanceManager.onHostPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mReactInstanceManager.onHostResume(this, this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mReactInstanceManager.onHostDestroy(this);
        mReactRootView.unmountReactApplication();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        mReactInstanceManager.onBackPressed();
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_MENU){
            mReactInstanceManager.showDevOptionsDialog();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public void invokeDefaultOnBackPressed() {
        super.onBackPressed();
    }
}

Steps to reproduce

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

React Native Version

0.76.6

Affected Platforms

Runtime - Android

Areas

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

2025-01-12 09:47:42.440 14499-14499 jni_lib_merge           com.coffeeai                         D  About to register 3 actual methods.
2025-01-12 09:47:42.442 14499-14499 SoLoader                com.coffeeai                         W  SoLoader already initialized
2025-01-12 09:47:42.632 14499-14541 TrafficStats            com.coffeeai                         D  tagSocket(103) with statsTag=0xffffffff, statsUid=-1
2025-01-12 09:47:42.633 14499-14540 TrafficStats            com.coffeeai                         D  tagSocket(98) with statsTag=0xffffffff, statsUid=-1
2025-01-12 09:47:42.634 14499-14542 TrafficStats            com.coffeeai                         D  tagSocket(106) with statsTag=0xffffffff, statsUid=-1
2025-01-12 09:47:42.645 14499-14540 unknown:ReactNative     com.coffeeai                         W  The packager does not seem to be running as we got an IOException requesting its status: Failed to connect to /10.0.2.2:8081
2025-01-12 09:47:42.647 14499-14541 unknown:Re...gWebSocket com.coffeeai                         W  Couldn't connect to "ws://10.0.2.2:8081/message?device=sdk_gphone64_x86_64%20-%2013%20-%20API%2033&app=com.coffeeai&clientid=BridgeDevSupportManager", will silently retry
2025-01-12 09:47:42.669 14499-14517 Parcel                  com.coffeeai                         W  Expecting binder but got null!
2025-01-12 09:47:42.683 14499-14499 unknown:ReactNative     com.coffeeai                         W  Packager connection already open, nooping.
2025-01-12 09:47:42.702 14499-14517 OpenGLRenderer          com.coffeeai                         E  Unable to match the desired swap behavior.
2025-01-12 09:47:42.856 14499-14499 unknown:ReactNative     com.coffeeai                         W  Packager connection already open, nooping.
2025-01-12 09:47:42.857 14499-14549 AndroidRuntime          com.coffeeai                         E  FATAL EXCEPTION: mqt_native_modules
                                                                                                    Process: com.coffeeai, PID: 14499
                                                                                                    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:463)
                                                                                                    	at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:474)
                                                                                                    	at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:458)
                                                                                                    	at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:95)
                                                                                                    	at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:52)
                                                                                                    	at com.facebook.react.ReactInstanceManager.attachRootViewToInstance(ReactInstanceManager.java:1320)
                                                                                                    	at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1269)
                                                                                                    	at com.facebook.react.ReactInstanceManager.lambda$runCreateReactContextOnNewThread$1(ReactInstanceManager.java:1232)
                                                                                                    	at com.facebook.react.ReactInstanceManager.$r8$lambda$gb653mFZ5g89YrL4JOidj7UzBRU(Unknown Source:0)
                                                                                                    	at com.facebook.react.ReactInstanceManager$$ExternalSyntheticLambda3.run(D8$$SyntheticClass:0)
                                                                                                    	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.lambda$startNewBackgroundThread$2(MessageQueueThreadImpl.java:217)
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
                                                                                                    	at java.lang.Thread.run(Thread.java:1012)
2025-01-12 09:47:42.920 14499-14549 Process                 com.coffeeai                         I  Sending signal. PID: 14499 SIG: 9
---------------------------- PROCESS ENDED (14499) for package com.coffeeai ----------------------------

Reproducer

none

Screenshots and Videos

截屏2025-01-12 08 27 58
@HeLiHuang HeLiHuang added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Jan 12, 2025
@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Jan 12, 2025
@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@princektripathi
Copy link
Collaborator

@HeLiHuang, can you please share a repro to validate the issue?

@HeLiHuang
Copy link
Author

@HeLiHuang, can you please share a repro to validate the issue?

git@github.com:HeLiHuang/react-native.git

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jan 13, 2025
@HeLiHuang
Copy link
Author

我想用ReactInstanceManager动态加载jsbundle文件,这要可以灵活的加载多个完全不同的jsbundle文件
I want to use ReactInstanceManager to dynamically load jsbundle files, which should be able to flexibly load multiple completely different jsbundle files

@cortinico cortinico added Needs: Author Feedback and removed Needs: Attention Issues where the author has responded to feedback. labels Jan 13, 2025
@cortinico
Copy link
Contributor

@HeLiHuang the reproducer you provided is not valid. It's hard to help you without a reproducer.

Anyway by looking at your code, I'd say you should make those changes:

public class RNBaseActivity extends Activity implements DefaultHardwareBackBtnHandler {
    private static final String TAG = "RNBaseActivity";
-   private ReactInstanceManager mReactInstanceManager;
    private ReactRootView mReactRootView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
-       mReactInstanceManager = ReactInstanceManager.builder()
-               .setApplication(getApplication())
-               .setCurrentActivity(this)
-               .setBundleAssetName("index.android.bundle")
-               .setJSMainModulePath("index")
-               .addPackage(new MainReactPackage())
-               .addPackage(new MyPackage())
-               .setUseDeveloperSupport(BuildConfig.DEBUG)
-               .setInitialLifecycleState(LifecycleState.RESUMED)
-               .build();


-       mReactRootView = new ReactRootView(this);
-       mReactRootView.startReactApplication(mReactInstanceManager, "IotReactNativeApp", null);
-       setContentView(mReactRootView);
    }


    @Override
    protected void onPause() {
        super.onPause();
-       mReactInstanceManager.onHostPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
-       mReactInstanceManager.onHostResume(this, this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
-       mReactInstanceManager.onHostDestroy(this);
-       mReactRootView.unmountReactApplication();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
-       mReactInstanceManager.onBackPressed();
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_MENU){
-           mReactInstanceManager.showDevOptionsDialog();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    public void invokeDefaultOnBackPressed() {
        super.onBackPressed();
    }
}

The problem here is that you're invoking methods on the ReactInstanceManager class which is a old-architecture only class.

This is how the default activity looks like:
https://github.com/react-native-community/template/blob/main/template/android/app/src/main/java/com/helloworld/MainActivity.kt

You should not be manipulating it further unless you have a specific reason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/facebook/react-native/issues/48622

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy