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

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

我做错了什么?


当前回答

我也遇到过这个问题。我解决了下面这一步。

在Environment Veritable中检查android sdk路径。

添加 系统变量中的ANDROID_HOME = C:\Users\user_name\AppData\Local\Android\Sdk 而且 C:\Users\user_name\AppData\Local\Android\Sdk\platform-tools路径在“系统变量”中

替换sharedBlacklist如下代码段

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

在node_modules / metro-config / src / / blacklist.js违约

然后执行npx react-native run-android——port 9001

编码. .快乐!

其他回答

    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

类似的问题也发生在我身上。 显然Mcafee阻塞了8081端口。我花了好几个小时才弄明白。

尝试运行:

react-native run-android --port=1234

当应用程序在模拟器上显示错误时,进入开发设置(Ctrl+M)。

将“调试服务器主机和设备端口”更改为“localhost:1234”。

关闭应用程序,并从应用程序抽屉启动它。

关闭代理,如果你在android studio设置代理,默认使用代理

对我来说,这个错误是由react-native的升级引起的

从Android 9.0 (API级别28)开始,默认情况下禁用明文支持。

如果您检查了升级差异,您需要创建一个调试清单 android / app / src /调试/ AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>

查看更多信息:https://stackoverflow.com/a/50834600/1713216

https://react-native-community.github.io/upgrade-helper/

默认情况下,一个名为“Metro server”的小型JavaScript服务器运行在端口8081上。

您需要使此端口可用于此服务器启动。所以,

释放端口 关闭虚拟设备 “react-native run-android”。

如何释放端口?

http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html

如何在windows中杀死当前使用本地主机端口的进程?

最重要的是,我从8升级了我的节点版本。X到10.x(最新),正如facebook建议的那样 @ https://facebook.github.io/react-native/docs/getting-started