我试图在我的设备上第一次运行我的第一个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
当前回答
照着做,对我有用。
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
其他回答
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。
照着做,对我有用。
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
在我的例子中,我已经从MainApplication.java中删除了以下一行。(这是我之前错误添加的):-
进口com.facebook.react.BuildConfig;
之后,清洁项目和点击命令
react-native运行android
这是一个常见的错误消息,您可能在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模拟器中运行。
我也面临着这个问题,因为当我在模拟器上运行项目时,它的工作很好,但在真实的设备上,它给出了这个错误。所以我用下面的方法来解决这个问题
第一步:首先打开cmd,进入SDK管理器Platform-tools文件夹
cd C:Development\Android\Sdk\Platform-tools
第二步:现在运行这个命令:
adb devices
执行此命令后,检查命令提示符中列出的设备
第三步:现在运行这个
adb reverse tcp:8081 tcp:8081
现在您的设置完成了
第四步:进入您的项目目录并运行此命令
react-native run-android