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

我得到:

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

我使用的命令:

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


当前回答

The most upVoted answer seems working but become hectic for developers to see their minor changes after couple of minutes. I solved this issue by following these steps: 1- Push my code to bitbucket/github repo ( to view the changes later ) 2- cut paste android folder to any safe location for recovery 3- delete the android folder from my project 4- run react-native upgrade 5- Now, I see all the changes between the previous and the lastest build (using VsCode) 6- I found the issue in build.gradle file in these lines of code.

ext {
buildToolsVersion = "28.0.2"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 27
supportLibVersion = "28.0.0"
}

7-我复制了这些行(由react-native升级脚本生成,并再次删除android文件夹。 8-然后我剪切粘贴android文件夹回到我的项目文件夹,我在第2步剪切粘贴。 9 -替换构建。Gradle文件行与复制的。 10-现在工作正常。

希望这对你有所帮助。

其他回答

在我的例子中,我已经从MainApplication.java中删除了以下一行。(这是我之前错误添加的):-

进口com.facebook.react.BuildConfig;

之后,清洁项目和点击命令

react-native运行android

如果已经尝试了以上所有解决方案,但仍然遇到错误。 试着和我一样配置你的genymotion:

我的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 start

then

adb reverse tcp:8081 tcp:8081

在命令行上。然后我可以运行:

react-native run-android

所以我不会浪费时间去跑:

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

每一次。

在命令之前使用NPX对我来说是有效的,命令就像下面这样。

npx 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

为什么我们使用npx,这里是npx和npm之间的区别?