我试图在我的设备上第一次运行我的第一个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
当前回答
在命令之前使用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之间的区别?
其他回答
使用npm 4.3.0版本的react-native-cli
在项目目录中,
mkdir android / app / src / main /资产 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
文件名由index.android.js更改为index.js
首先检查你的assets文件夹是否存在于这个位置\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
然后在android设备上使用
react-native run-android
Ubuntu
第一次,我用react-native init project-name创建了新的应用程序。 我得到了同样的错误。 所以在我的例子中,我执行以下步骤来解决这个问题。
首先执行sudo chown user-name-of-pc /dev/kvm。 从Android手机调试时,选择“使用USB传输照片(PTP)”。 在project-name/android/app/src/main中创建文件夹资产 确保index.js在你的项目根目录下可用,然后从控制台在CD项目名称目录后运行下面的命令。
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
或 对于index.android.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
在“android-studio/bin”目录下执行。/studio.sh命令。它将开放Android Studio。 执行命令react-native Run -android。
如果您使用的是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
实际上,在我的情况下(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
]