我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。
我得到:
无法从assets index.android.bundle中加载脚本
我使用的命令:
CD(项目目录) react-native开始 react-native运行android
当前回答
IOS:
在终端中:
cd ios
使用:rm -r build删除build文件夹
再次运行:react-native Run -ios
或者,你可以打开Finder,导航到YOUR_PROJECT/ios并删除构建文件夹。
然后再次运行:react-native run-ios
为ANDROID:
在终端中:
cd android/app
使用:rm -r build删除build文件夹
再次运行:react-native Run -android
或者,你可以打开Finder,导航到YOUR_PROJECT/android/app并删除构建文件夹。
然后再次运行:react-native run-android
其他回答
如果已经尝试了以上所有解决方案,但仍然遇到错误。 试着和我一样配置你的genymotion:
当我试图调试我的代码时,我有这个问题(在我的android手机和react开发中使用Toggle检查器),我做了以下简单的步骤:
在手机中打开菜单(在重载的地方,我可以通过长按后退键或摇晃手机来打开它) 在这里输入图像描述 点击“开发设置” 在调试->调试服务器主机和设备端口应该为空 注意:如果你在这里写了port或任何东西(用于调试),你应该清除它。
如果你在你的主AndroidManifest.xml中定义了android:networkSecurityConfig,这个问题也会发生。android:usesCleartextTraffic="true"在你的调试AndroidManifest.xml将被忽略。
要解决这个问题,你必须配置应用程序允许http流量到localhost。
创建一个文件android/src/debug/res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8" ?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
</domain-config>
</network-security-config>
并在android/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:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning" />
</manifest>
更多信息请访问:https://medium.com/astrocoders/i-upgraded-to-android-p-and-my-react-native-wont-connect-to-my-computer-to-download-index-delta-42580377e1d3
实际上,在我的情况下(React-native版本0.61.5,并试图在设备上安装调试APK)没有一个答案帮助我,我的解决方案是添加bundleInDebug: true到android/app/build。这样Gradle:
project.ext.react = [
entryFile: "index.js",
enableHermes: true, // clean and rebuild if changing
bundleInDebug: true
]
使用npm 4.3.0版本的react-native-cli
在项目目录中,
mkdir android / app / src / main /资产 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
文件名由index.android.js更改为index.js