我试图在我的设备上第一次运行我的第一个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
当前回答
确保metro构建器正在运行,以使物理设备和服务器同步
首先,运行这个命令来运行metro builder
npm开始
然后你可以在react native中开始构建
react-native运行android
他们这次应该不会出错了。如果您希望您的代码在更改时重新加载。摇动你的设备,然后点击“启用Live Reload”
其他回答
照着做,对我有用。
https://github.com/react-community/lottie-react-native/issues/269
进入你的项目目录,检查这个文件夹是否存在android/app/src/main/assets i)如果它存在,那么删除两个文件即index.android.bundle和index.android.bundle.meta ii)如果assets文件夹不存在,那么在那里创建assets目录。
从您的根项目目录做 CD android && ./gradlew clean
最后,导航回根目录,检查是否有一个名为index.js的条目文件 i)如果只有一个文件,即index.js,则执行以下命令 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
ii)如果有两个文件,即index.android.js和index.ios.js,那么运行这个 React-native bundle——platform android——dev false——entry-file index.android.js——bundle-output android/app/src/main/assets/index.android. jsBundle——assets-dest android/app/src/main/res
现在运行react-native run-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";
}
};
在尝试进行产品构建时,可能必须恢复更改。
当我更新react-native到0.49.5时,这个问题出现了,当我遵循这个破坏性的变化和弃用
它就消失了。
确保你已经在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 }
实际上,在我的情况下(React-native版本0.61.5,并试图在设备上安装调试APK)没有一个答案帮助我,我的解决方案是添加bundleInDebug: true到android/app/build。这样Gradle:
project.ext.react = [
entryFile: "index.js",
enableHermes: true, // clean and rebuild if changing
bundleInDebug: true
]