Bel*_*ons 82 reactjs react-native react-native-android react-native-cli metro-bundler
react-native run-android通过在android仿真器中的消息中保留一条消息来终止。消息如下
无法加载脚本。请确保您正在运行Metro服务器,或者已正确捆绑了软件包“ index.android.bundle”以进行发布。
我完全感到困惑,这是在做错什么。
编辑:添加错误屏幕截图
Ner*_*gen 45
您尚未启动捆绑器。在运行npm start或react-native start直接在项目的根目录之前react-native run-android
Sae*_*eed 32
这些步骤确实对我有帮助:
步骤1:在android / app / src / main / assets中创建目录
Linux命令:mkdir android/app/src/main/assets
第2步:将index.android.js(在根目录中)重命名为index.js(也许有一个index.js文件,在这种情况下您不需要重命名),然后运行以下命令:
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
步骤3:
建立APK:react-native run-android
请使用最新版本的index.js。
请享用 :)
Tom*_*Tom 26
对我来说,这个错误是由react-native的升级引起的
从Android 9.0(API级别28)开始,默认情况下禁用明文支持。
如果签出升级差异,则需要创建调试清单
android/app/src/debug/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>
Run Code Online (Sandbox Code Playgroud)
看到更多信息:https : //stackoverflow.com/a/50834600/1713216
https://react-native-community.github.io/upgrade-helper/
Abo*_*zlR 17
首先执行第 4 步和第 5 步,然后您就可以运行您的项目了。如果没有得到结果(第 4 步和第 5 步),请执行以下步骤
1-尝试降级您的 Node 版本(当前版本是12.13.1)
choco uninstall nodejs
choco install nodejs --version 12.8
Run Code Online (Sandbox Code Playgroud)
2-将 npm 模块 ( C:\Users\your user name\AppData\Roaming\npm)的路径添加到系统变量而不是用户变量
3-使用命令全局安装本机反应
npm install -g react-native-cli
Run Code Online (Sandbox Code Playgroud)
4-转到项目目录的根目录并运行以下命令:
react-native start
Run Code Online (Sandbox Code Playgroud)
5-在项目的根目录中打开另一个终端并运行以下命令:
react-native run-android
Run Code Online (Sandbox Code Playgroud)
编辑 :
您正在使用 Genymotion 吗?如果是,请执行以下步骤:
执行上述步骤后是否出现以下错误?
error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.
Run Code Online (Sandbox Code Playgroud)
打开您的 genymotion 并转到:
genymotion menu -> Settings -> ADB -> 然后选择use custom android sdk tools(点击浏览找到sdk位置)
最后,再次运行你的项目..
Jav*_* C. 12
在我的工作区中尝试解决这个问题后,我找到了一个解决方案。
这个错误是因为使用 NPM 和 Node 版本的某些组合的 Metro 存在问题。
您有 2 个选择:
备选方案 2: 转到此文件:\node_modules\metro-config\src\defaults\blacklist.js并更改此代码:
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
Run Code Online (Sandbox Code Playgroud)
并更改为:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
Run Code Online (Sandbox Code Playgroud)
请注意,如果您运行 an
npm install或 ayarn install,则需要再次更改代码。
Man*_*aya 10
在尝试了多种方法后,这对我有用。
在文件中 node_modules\metro-config\src\defaults\blacklist.js
代替 :
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
Run Code Online (Sandbox Code Playgroud)
和 :
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
您可以尝试以下方法:
在您的AndroidManifest.xml上添加此行
<application
[...]
android:usesCleartextTraffic="true"
/>
[...]
</application>
Run Code Online (Sandbox Code Playgroud)
小智 8
从 Android 9.0(API 级别 28)开始,默认情况下禁用明文支持。
如果您正确执行正常运行命令,这就是您需要做的来摆脱这个问题
并像这样修改您的android清单文件。
<application
android:name=".MainApplication"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true" // add this line with TRUE Value.
android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)
就我而言,我尝试在模拟器上运行应用程序。但是,我得到了这个
这个IP 10.0.2.2可以从模拟器chrome浏览器访问。问题是该 IP 未在 Android 网络安全设置中列入白名单。因此,无论您在此处看到什么 IP 地址,请将其添加到以下设置中,然后就可以开始了。
./android/app/src/main/AndroidManifest.xml
<application
android:name=".MainApplication"
+ android:usesCleartextTraffic="true" <- Add this line
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
./android/app/src/main/res/xml/network_security_config.xml
</network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.0.1.1</domain>
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">10.0.3.2</domain>
</domain-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
只需替换<domain includeSubdomains="true">10.0.2.2</domain>为您在react-native错误中显示的IP即可。
小智 7
我发生了类似的问题显然,Mcafee阻塞了8081端口,这花了我几个小时才弄清楚
尝试运行react-native run-android --port = 1234
应用在模拟器上显示错误后,进入开发设置(可通过单击crtl + M进行访问)
将“调试设备的服务器主机和端口”更改为“ localhost:1234”
关闭应用程序,然后从应用程序抽屉启动它
希望这对您有帮助!!
小智 7
我在学习 React Native教程(在 Linux 上开发并针对 Android)时遇到了同样的问题。
这个问题帮助我解决了以下步骤中的问题。按以下顺序运行以下命令:
mkdir android/app/src/main/assetsreact-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/resreact-native run-android您可以通过将上述步骤放在这样的scripts部分中来自动化上述步骤package.json:
"android-linux": "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 && react-native run-android"
Run Code Online (Sandbox Code Playgroud)
然后您npm run android-linux每次都可以从命令行执行。
两个答案的结合解决了我的问题。这是与港口有关的。
adb reverse tcp:8088 tcp:8088
react-native run-android --port=8088
Run Code Online (Sandbox Code Playgroud)
通过这样做,应用程序可以很好地加载通过 USB 连接的手机。我认为我的 AV 或 Vagrant 或我 PC 中的其他东西正在使用该端口。
如果需要,您可以将 8088 更改为其他名称。
如果您正确配置了所有内容,请尝试以下操作:
亚行反向tcp:8081 tcp:8081
为什么?“当RN打包程序运行时,您的浏览器中将有一个活动的Web服务器,其访问位置为127.0.0.1:8081。正是通过此服务器为您的应用程序提供了JS捆绑包,并在您进行更改时对其进行了刷新。如果没有反向代理,您的电话将无法连接到该地址。”
所有学分归功于Swingline0
小智 6
如果您使用的是 linux,请从 App 根目录打开终端并运行
npm start
Run Code Online (Sandbox Code Playgroud)
然后打开另一个终端窗口并运行:
react-native run-android
Run Code Online (Sandbox Code Playgroud)
只需在其中添加三个启动器:node_modules \ metro-config \ src \ defaults \ blacklist.js
替换此部分:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
Run Code Online (Sandbox Code Playgroud)
像我们大多数人一样,我假设您正在运行 VSCODE。就我而言,我跑了
npx react-native start
从一个单独的终端
现在在 VSCODE 中从终端运行 npx react-native run-android
| 归档时间: |
|
| 查看次数: |
47673 次 |
| 最近记录: |