我使用的是使用纱线工作区创建的MonorePo,其中包含一个具有反应的(0.68.2)项目(移动文件夹)的TypeScript和一个公共文件夹,其中包含在项目中要共享的通用文件。在这里,移动项目取决于公共文件,我将其配置为参考此。
从Android开始,该应用在调试模式下运行良好。当我创建发行版构建时,APK将成功生成。安装应用程序后,打开时,它会在打开后立即崩溃。在观察错误时,捆绑包似乎存在问题。我尝试手动运行 bundle 命令包装它并尝试生成APK,但仍会导致相同的错误。
logcat的错误:
2022-06-03 22:36:28.457 5699-5723/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: com.myapp.mobile, PID: 5699
java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:248)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:29)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:277)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1422)
at com.facebook.react.ReactInstanceManager.access$1200(ReactInstanceManager.java:138)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1111)
at java.lang.Thread.run(Thread.java:923)
有什么建议吗?
I am using monorepo created using Yarn Workspaces with Typescript which has a react-native (0.68.2) project (mobile folder) and a common folder which contains the common files to be shared across projects. Here the mobile project is dependent on common files and I have configured it referring to this doc.
Starting with Android, the app runs fine in debug mode. When I create a release build, the apk is generated successfully. After installing the app, on opening, it crashes as soon as it opens. On observing the error, it looks like there is a problem with the bundle. I tried manually running the bundle command for packing it and tried generating the apk, but it still results in the same error.
Error from LogCat:
2022-06-03 22:36:28.457 5699-5723/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: com.myapp.mobile, PID: 5699
java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:248)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:29)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:277)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1422)
at com.facebook.react.ReactInstanceManager.access$1200(ReactInstanceManager.java:138)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1111)
at java.lang.Thread.run(Thread.java:923)
Any Suggestions?
发布评论
评论(1)
捆绑包被包装并放置在错误的路径中,这导致了此错误。
始终应包装捆绑包并仅在此路径
Android \ App \ Src \ Main \ Assets \ Index.android.bundle.Bundle
for Android中。以下命令将正确执行。The bundle was packed and placed in the wrong path which was causing this error.
Always the bundle should be packed and placed in only in this path
android\app\src\main\assets\index.android.bundle
for android. The below command will do it correctly.