我试图在我的设备上第一次运行我的第一个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
当前回答
提出一个显而易见的建议,对我很有用。删除应用程序,重新启动服务器,重新从工具部署到设备。
其他回答
即使在模拟器上运行,我也遇到了同样的问题。我做了一个快速的变通,这样我就可以拥有正常的开发工作流程。
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
// return true here to load JS from the packager
// BuildConfig.DEBUG for me was set to false which meant it
// it was always trying to load the assets from assets folder.
return true;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
在尝试进行产品构建时,可能必须恢复更改。
如果您使用的是Windows,则按照以下方式运行命令,或者如果您得到错误“无法找到入口文件index.android.js”
mkdir android主要\ app \ src \ \资产 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
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-现在工作正常。
希望这对你有所帮助。
在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**
]
这是一个常见的错误消息,您可能在react本机应用程序开发过程中遇到过。所以在本教程中,我们将为这个问题提供解决方案。
问题描述: 无法在windows上从assets index.android.bundle中加载脚本 无法在windows上从assets index.android.bundle中加载脚本
按照以下步骤解决上述问题:
步骤1:在项目目录中创建“assets”文件夹 现在在项目目录中创建资产文件夹,名为“MobileApp\android\app\src\main”。您可以手动创建资产文件夹:
<或>
您也可以使用命令创建文件夹。 命令: mkdir android / app / src / main /资产
步骤2:运行React Native应用程序 让我们运行下面的命令在模拟器或物理设备中运行react本机应用程序。
切换到项目目录。 cd MobileApp
运行下面的命令来帮助捆绑你的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
运行最后一步,在模拟器或物理设备中运行react本机应用程序。 react-native运行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 && react-native run-android
<或>
您可以通过将上述步骤放在包的脚本部分来自动化它们。Json是这样的:
“android-android”:“react-native bundle——platform android——dev false——entry-file index.js——bundle-output android/app/src/main/assets/index.android. js”Bundle——assets-dest android/app/src/main/res && react-native run-android"
如果一切设置正确,您应该很快就会看到新应用程序在Android模拟器中运行。