React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:
无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。
我做错了什么?
当前回答
对我有效的解决方案如下:
var sharedBlacklist = [
/node_modules[\/\\]react[\/\\]dist[\/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
其他回答
在某些情况下,您可能需要关闭React-native捆绑器的端口 用相同的进程重新运行应用程序
1.sudo kill -9 $(sudo lsof -t -i:9001)
2.npm start inside the project
3. react-native run-android
在我的例子中,我试图在模拟器上运行应用程序。但是,我得到了这个
这个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>
只需将<domain inclesubdomains ="true">10.0.2.2</domain>替换为react-native错误中显示的IP。
在重命名我的android包ID后,我在React Native v0.69中遇到了这个问题。
将/android/app/src/debug/java/old_package_name重命名为 /android/app/src/debug/java/new_package_name,我不小心将AndroidManifest.xml的调试版本移动到新创建的路径中。
在把它移回/android/app/src/debug/后,yarn android又可以正常工作了,没有做任何其他的解决方案。有趣的是,这个错误导致了这个错误,所以如果它发生在其他人身上,检查确保你的文件在他们应该在的地方。
下面这些步骤真的对我很有帮助:
步骤1:在android/app/src/main/assets目录下创建一个目录
Linux命令:mkdir android/app/src/main/assets
第二步:将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。
享受:)
我在学习React Native教程时也遇到过同样的问题(在Linux上开发,目标是Android)。
这个问题帮助我通过以下步骤解决了问题。按如下顺序执行以下命令:
(在项目目录)mkdir android/app/src/main/assets 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运行android
您可以通过将上述步骤放在包的脚本部分来自动化它们。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"
然后你可以每次都从你的命令行执行npm run android-linux。