我试图在我的设备上第一次运行我的第一个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
当前回答
在Windows上
如果你确定node.js已经成功安装在你的系统上,请检查系统环境变量并在系统变量路径中添加C:\windows\system32
其他回答
我花了几个小时试图解决这个问题。我的问题不是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
我刚刚遇到了完全相同的问题,并解决了它。希望对大家有所帮助。
假设您正在组装一个发布应用程序包(.apk)
Check if your assets folder exist?: \android\app\src\main\assets If not, create one. After executing "Assemble Release", check if there is anything in that folder(\android\app\src\main\assets) If not, find js bundle file(index.android.bundle), which should be in more than one of the following paths: *a)\android\app\build\intermediates\merged_assets\release\out\index.android.bundle b)\android\app\build\intermediates\merged_assets\release\mergeReleaseAssets\out\index.android.bundle c)\android\app\build\intermediates\assets\release\index.android.bundle d)\android\app\build\generated\assets\react\release\index.android.bundle*
更好的方法是使用“Everything”来搜索文件名:index.android.bundle。
然后将这个文件复制到你的assets文件夹(\android\app\src\main\assets\index.android.bundle) 回到powershell或命令控制台,执行:
React-native run-android——variant=release
它应该会起作用。
好运!
此问题也可能是由于设备/模拟器的蜂窝数据被关闭引起的。一定要检查一下。
如果您正在物理设备上运行应用程序并得到此错误
unable to load script from assets index.android.bundle
试着运行命令:
adb reverse tcp:8081 tcp:8081
这对我很管用……
确保你已经在path变量中添加了/path/to/sdk/platform-tools。
当你运行react-native run-android时,它会运行adb reverse tcp:< device-port > tcp:< local-port >命令将请求从你的设备转发到你计算机上本地运行的服务器。 如果没有找到adb,您将看到类似这样的内容。
/bin/sh: 1: adb: not found
Starting the app (.../platform-tools/adb shell am start -n
com.first_app/com.first_app.MainActivity...
Starting: Intent { cmp=com.first_app/.MainActivity }