错误“无法获取BatchedBridge,请确保您的捆绑包包装正确".在应用启动时 [英] error "Could not get BatchedBridge, make sure your bundle is packaged properly" on start of app
问题描述
尝试在Android 4.4.2上创建本机项目时,出现此错误屏幕
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屋!