electrode-io / electrode-native

A platform to ease integration&delivery of React Native apps in existing mobile applications

Home Page:https://native.electrode.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: 'Miniapp has not been registered ....' , crash in release apk when native parent app is a React Native Project

adiwon9555 opened this issue · comments

With native app as android, release builds are working fine… but with react-native as native app, release build is not working as expected.
Somehow its still trying to get the code from metro-bundler in release build also.
Error:

2021-07-15 02:07:42.276 1717-1761/com.nativeappelectrode64 E/ReactNativeJS: Invariant Violation: "ClassroomMiniapp" has not been registered. This can happen if:
    * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
    * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
2021-07-15 02:07:42.303 1717-1762/com.nativeappelectrode64 E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.nativeappelectrode64, PID: 1717
    com.facebook.react.common.JavascriptException: Invariant Violation: "ClassroomMiniapp" has not been registered. This can happen if:
    * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
    * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., stack:
    exports@26:286
    runApplication@336:1408
    value@41:3469
    <unknown>@41:662
    value@41:2459
    value@41:634
    value@-1
    
        at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:83)
        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:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:907)
    	at android.os.

Have tried the following but with no success:
1)Enabled or disabled hermes in both side
2)set isReactNativeDeveloperSupport(false) or isReactNativeDeveloperSupport(true) or isReactNativeDeveloperSupport(BuildConfig.DEBUG)

Also ran the following command to get detailed stacktrace :
npx metro-symbolicate android/app/build/generated/sourcemaps/react/release/index.android.bundle.map < stacktrace.txt

Detailed stacktrace:

2021-07-15 /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/react-native/index.js:117:<global>.276 1717-1761/com.nativeappelectrode64 E/ReactNativeJS: Invariant Violation: "ClassroomMiniapp" has not been registered. This can happen if:
    * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
    * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
2021-07-15 /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/react-native/index.js:117:<global>.303 1717-1762/com.nativeappelectrode64 E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.nativeappelectrode64, PID: 1717
    com.facebook.react.common.JavascriptException: Invariant Violation: "ClassroomMiniapp" has not been registered. This can happen if:
    * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
    * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., stack:
    /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/invariant/browser.js:38:invariant
    /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/react-native/Libraries/ReactNative/AppRegistry.js:193:runApplication
    /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:414:__callFunction
    /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:113:__guard$argument_0
    /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:365:__guard
    /Users/VIPL1920L031/Desktop/vedantu/codes/reactNative/experiments/nativeAppElectrode64/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:112:callFunctionReturnFlushedQueue
    value@-1
    
        at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:83)
        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:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.⏎  

Please help.

Found the issue:
it was the name conflict of index.android.bundle in react-native parent app and mini-app.
The react native host of mini-app was trying to fetch code from main app's index.android.bundle.

So as a work around I changed the container code, inside ElectrodeReactContainer.java with

protected String getBundleAssetName() {
            return "indexmini.android.bundle";
        }

also changed the index.android.bundle inside assets to indexmini.android.bundle.

But this I had to do manually.
It would be great if this could be added as cli command of create-container.

Or if there is a better way, please let me know.