我试图在我的设备上第一次运行我的第一个React Native项目(Android 4.2.2)。

我得到:

无法从assets index.android.bundle中加载脚本

我使用的命令:

CD(项目目录) react-native开始 react-native运行android


当前回答

我在学习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。

其他回答

我的mac上的McAfee阻塞端口8081,不得不将其更改为8082。

首先运行你的包服务器:

react-native start --port 8082

打开另一个终端,像往常一样启动android应用程序:

react-native run-android

一旦它完成,现在重写adb隧道的tcp端口:

adb reverse tcp:8081 tcp:8082

查看adb tcp隧道列表:

adb reverse --list

你现在应该会看到一条温馨的信息:

(reverse) tcp:8081 tcp:8082

回到你的应用程序,重新加载,完成!

PS:不要在应用程序开发设置中更改任何内容,如果你添加了“localhost:8082”,只需删除它,让它为空。

编辑: 对于所有的McAfee受害者,如果你有根访问权限,有一个更简单的解决方案,只是暂时关闭位于端口8081的McAfee进程,根本不需要更改端口:

sudo launchctl remove com.mcafee.agent.macmn

当我更新react-native到0.49.5时,这个问题出现了,当我遵循这个破坏性的变化和弃用

它就消失了。

我面临着这个问题,很多搜索,我解决了这个问题。

c:\ProjectFolder\ProjectName> 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:

c: \ ProjectFolder \ ProjectName > react-native运行android

在MAC或Windows上,我们可以在1秒内解决这个问题

在你的项目中搜索project.ext.react这个术语

并在bundleInDebug: true中做一个更改,添加这一行。并再次运行您的项目。

    project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    bundleInDebug: true  // **add this line only**
]

我在真正的android设备上也遇到过同样的问题。

解决方案:基于Niltoid的回答

查找本地IP 打开应用程序,摇晃你的安卓设备 去开发设置和>调试服务器… 粘贴你的IP和端口;X.X.X.X:8088"(其中X是您的本地IP)

Mac用户:打开你的网络首选项,在这里你会得到你的本地IP。