android - 在 Android 中 react native 多包

标签 android react-native bundle

我有另一个 RN 项目并将其生成为一个包(名为:appA.bundle),其中包含 app.js 注册组件“ProjectA”。

在我的主要 RN 项目或说框架项目(包名称:index.bundle)中,app.js 注册组件“MainProject”,我想调用 appA.bundle。但是,它不起作用。有谁能给点建议吗?

非常感谢。

以下代码用于在 Android Studio 中调用 bundle。

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

 mReactRootView = new ReactRootView(this);
 mReactInstanceManager = ReactInstanceManager.builder()
         .setApplication(getApplication())
         .setBundleAssetName("appA.bundle")
         .setJSMainModulePath("index")
         .addPackage(new MainReactPackage())
         .setUseDeveloperSupport(BuildConfig.DEBUG)
         .setInitialLifecycleState(LifecycleState.RESUMED)
         .build();

 mReactRootView.startReactApplication(mReactInstanceManager, "ProjectA", null);

 setContentView(mReactRootView);
}

Android Studio logcat 中显示以下错误:

10-31 15:25:27.890 24965-28439/com.mainproject I/ReactNativeJS: Running application "ProjectA" with appParams: {"rootTag":51}. DEV === true, development-level warning are ON, performance optimizations are OFF

10-31 15:25:27.891 24965-28439/com.mainproject E/ReactNativeJS: Application ProjectA has not been registered.

Hint: This error often happens when you're running the packager (local dev server) from a wrong folder. For example you have multiple apps and the packager is still running for the app you were working on before.

If this is the case, simply kill the old packager instance (e.g. close the packager terminal window) and start the packager in the correct app folder (e.g. cd into app folder and run 'npm start').

This error can also happen due to a require() error during initialization or failure to call AppRegistry.registerComponent.

10-31 15:25:27.897 24965-24965/com.vendorproject E/unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: Application ProjectA has not been registered.

最佳答案

此错误是由于有 2 个不同的项目。您的代码正在通过调用 localhost:8081 来初始化第二个项目,您可能在该项目上运行了主程序。

为了让事情能够运行,我只是在没有 .setUseDeveloperSupport(BuildConfig.DEBUG) 的情况下运行代码,而子项目与 src/main/assets< 中的二进制文件 bundle 在一起文件夹

关于android - 在 Android 中 react native 多包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53404897/

相关文章:

c# - 如何为 Mac OS 创建一个 .app mono bundle

android - 在 startActivity() 上传递一个 Bundle?

java - 使用gson解析不同类型的Json对象

java - 从datasnapshot中获取特定值

android - 在没有第三方库的情况下将图像从网络加载到网格

javascript - 我可以将音频/视频对象从 expo-av 传递到 redux 状态吗?

javascript - JS包中包含图片

Android线程无法访问Main.xml

react-native - 使用 React Native 的透视动画抽屉?

Android 应用程序在发布版本时崩溃,但在调试版本中工作 - React-Native