React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:

无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。

我做错了什么?


当前回答

试试这个

taskkill /F /IM node.exe

然后

npx react-native run-android

其他回答

    this works for me on ubuntu
    
    1. if you are having node version 17 first downgrade its version:-
    You can use n for node's version management.
    
    this is very easy to use.
    $ npm install -g n
    
    then you can show your node version:
    $ node -v
    v16.13.2
    
    2. create an assets folder inside root of the project:-
    project\android\app\src\main\assets
    set folder name should be assets

3. now the final step implement the given code inside the project folder:- 

$cd project 
/project$ react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

4. after following all these step react-native was successfully running on my pc

如果你在linux上,从App根目录打开终端并运行

npm start

然后打开另一个终端窗口并运行:

react-native run-android

在地铁黑名单中更新此部分

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

我遇到了同样的麻烦,对我来说,问题是adb不在正确的环境路径,错误是告诉你地铁端口,而你在adb,端口被杀死并重新启动。

添加环境变量(ADB)

开放环境变量 从第二帧PATH变量中选择,然后单击下面的编辑选项 点击添加选项 提交sdk平台工具路径C:\Users\ My User \AppData\Local\Android\ sdk \platform-tools

注意:或取决于adb.exe在您的机器中的位置

保存更改

再次运行android build

$ react-native run-android

Or

$ react-native start

$ react-native run-android

我确信它是这里提到的其他东西的某种组合,比如允许明文,这是我为localhost启用的。但这是谜题的最后一块。

project.ext.react = [
    entryFile: "index.js",

    // ADD THESE THREE

    bundleAssetName: "index.android.bundle",
    bundleInDebug: true,
    bundleInRelease: true
]

RN: 0.61.3