错误“无法获得 BatchedBridge,请确保您的捆绑包已正确打包";在应用程序启动时 [英] error "Could not get BatchedBridge, make sure your bundle is packaged properly" on start of app

查看:35
本文介绍了错误“无法获得 BatchedBridge,请确保您的捆绑包已正确打包";在应用程序启动时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 Android 4.4.2 上创建 react-native 项目时出现此错误屏幕

Trying to create a react-native project on Android 4.4.2 I get this error screen

并且找不到任何解决方法.我尝试重新启动打包程序,重新连接设备,甚至重新安装 react native 并启动新项目.在 6.0.0 及更高版本上它工作得很好.

and couldn't find any way to resolve it. I tried restarting packager, reconnecting device, even reinstalling react native and starting new project. On 6.0.0 and later versions it works just fine.

推荐答案

一个可能的解决方案是,您很可能不会先捆绑您的应用程序,执行以下步骤,然后将您的 app-debug.apk 部署到您的设备

A possible solution for this is that you most probably not bundling your application first, perform the following steps and then deploy your app-debug.apk to your device

$ cd myproject  
$ react-native start > /dev/null 2>&1 &  
$ curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

(如果文件夹assets 不存在创建它)

(if the folder assets does not exists create it)

然后从项目根目录运行

$> (cd android/ && ./gradlew assembleDebug)

从以下位置将创建的 apk 安装到您的设备:android/app/build/outputs/apk/app-debug.apk

install the created apk to you device, from location: android/app/build/outputs/apk/app-debug.apk

如果这能解决您的问题,请告诉我

let me know if that fixes your issue

编辑:

你可以简单地把它作为一个脚本放在你的 package.json 中来自动化它,我相信它会在即将发布的 react-native 版本中得到修复,并且会在组装最终 APK 之前执行,因此这将是不需要的(我也希望如此)

You can simply put it to your package.json as a script to automate it, I believe it will be fixed in upcoming releases of react-native and will be executed prior assembling the final APK, hence this won't be needed (I hope as well)

放:

"scripts": {
    "build": "(cd android/ && ./gradlew assembleDebug)",
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "bundle-android": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.map --assets-dest android/app/src/main/res/"
  },

或者前面提到的 curl 等价物,但在大多数情况下,上面的更健壮

or as mentioned the curl equivalent, but for most cases the above is more robust

这篇关于错误“无法获得 BatchedBridge,请确保您的捆绑包已正确打包";在应用程序启动时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆