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

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

我做错了什么?


当前回答

试试这个命令

~/Library/Android/sdk/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081

其他回答

在尝试了几种方法后,这对我来说很有效。

在文件node_modules\metro-config\src\defaults\blacklist.js中

替换:

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

:

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

希望这能有所帮助。

只需添加三个飞溅: node_modules \ metro-config \ src \ \ blacklist.js违约

更换此部件:

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];
    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

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

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

首先执行步骤4和5,然后可以运行项目。如果您没有得到结果(步骤4和5),请执行以下步骤

1-尝试降级你的Node版本(当前版本是12.13.1)

  choco uninstall nodejs
  choco install nodejs --version 12.8

2-添加npm模块的路径(C:\Users\your user name\AppData\Roaming\npm)到系统变量而不是用户变量

3-使用命令全局安装react native

  npm install -g react-native-cli

4-进入项目目录的根目录,执行以下命令:

  react-native start

5-打开项目根目录下的另一个终端,执行以下命令:

   react-native run-android 

编辑:

你在用Genymotion ?是,执行以下步骤。

在以上步骤后,如果您得到以下错误?

error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.

打开你的genymotion,转到:

genymotion菜单->设置-> ADB ->然后选择使用自定义android sdk工具(点击浏览找到sdk位置)

最后,再次运行您的项目。