React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
(快速回答)
在我的工作空间尝试解决这个问题后,我找到了一个解决方案。
此错误是因为Metro使用NPM和Node版本的某些组合时出现了问题。
你有两个选择:
Alternative 1: Try to update or downgrade npm and node version. Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code: var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; and change to this: var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; Please note that if you run an npm install or a yarn install you need to change the code again.
其他回答
显然,没有一个答案能帮我解决这个问题。我能够在模拟器上运行反应本机应用程序,但相同的代码(即使服务器正在运行),在设备上运行应用程序时给了我这个错误。
我能够通过在终端中执行以下命令来解决它:
Adb reverse tcp:8081 tcp:8081
对我来说,这个错误是由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/
只需添加三个飞溅: node_modules \ metro-config \ src \ \ blacklist.js违约
更换此部件:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
我做了: react-native开始 而且 NPX react-native run-android。
然而,对于Min19,(基于Ubuntu的)我也有同样的问题,直到我运行:
echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
来自: https://reactnative.dev/docs/troubleshooting#content
至少我手机里还有软件在运行。
我确信它是这里提到的其他东西的某种组合,比如允许明文,这是我为localhost启用的。但这是谜题的最后一块。
project.ext.react = [
entryFile: "index.js",
// ADD THESE THREE
bundleAssetName: "index.android.bundle",
bundleInDebug: true,
bundleInRelease: true
]
RN: 0.61.3