我试图在我的设备上第一次运行我的第一个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
当前回答
首先检查你的assets文件夹是否存在于这个位置\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
然后在android设备上使用
react-native run-android
其他回答
1进入你的项目目录,检查这个文件夹是否存在android/app/src/main/assets
如果它存在,那么删除两个文件即index.android.bundle和index.android.bundle.meta 如果文件夹资产不存在,则在那里创建资产目录。
2.从您的根项目目录做
cd android && ./gradlew clean
3.最后,导航回根目录,检查是否有一个名为ledindex.js的条目文件
If there is only one file i.e. index.js then run following command 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 If there are two files i.e index.android.js and index.ios.js then run this react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res Now run react-native run-android
使用mkdir…/assets && react-native bundle——平台..不能完全解决这个问题,
注意,你必须在每次代码编辑时运行这个命令重新生成文件,并且在重新加载或远程调试JS后再次显示错误。
这个问题的根本原因是你的应用程序无法连接到服务器(因为一些未知的原因)
以下是我的解决方案:
首先,启动其他主机和端口上的服务,例如: React-native start——port 8082——host 0.0.0.0 然后打开应用程序开发菜单> dev Setting >设备的调试服务器主机 输入youripv4address: 8082 dev菜单>重载
希望这能有所帮助
如果你在你的主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项目代码库中未链接的资产引起的,例如,当您重命名项目应用程序/包id或添加外部包时没有正确链接。
在你的项目根目录下试试:
react-native link
react-native run-android
我花了几个小时试图解决这个问题。我的问题不是Windows特有的,而是Android特有的。
在本地和模拟器的浏览器中访问开发服务器。唯一不能工作的是在应用程序中访问开发服务器。
从Android 9.0 (API级别28)开始,默认情况下禁用明文支持。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
查看更多信息: https://stackoverflow.com/a/50834600/1713216