我试图在我的设备上第一次运行我的第一个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
当前回答
这可能是由React Native项目代码库中未链接的资产引起的,例如,当您重命名项目应用程序/包id或添加外部包时没有正确链接。
在你的项目根目录下试试:
react-native link
react-native run-android
其他回答
操作系统:Windows
在尝试以上两种方法后,另一种方法可以解决这个问题 (因为我安装的SDK不在默认位置,如C:\users\"user_name"\appdata\local\ SDK)
如果您注意到命令行显示:“‘adb’未被识别为内部或外部命令……”
这就是我克服的方法: 示例:我在D:\Android\ SDK中安装了SDK 所以我将在系统变量中插入path 2行:
D:\Android\sdk\tools
D:\Android\sdk\platform-tools
(如果你不知道如何编辑路径系统变量,这里是主题:https://android.stackexchange.com/questions/38321/what-do-i-type-in-path-variable-for-adb-server-to-start-from-cmd/38324)
然后再次运行cmd: 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
照着做,对我有用。
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
当我试图调试我的代码时,我有这个问题(在我的android手机和react开发中使用Toggle检查器),我做了以下简单的步骤:
在手机中打开菜单(在重载的地方,我可以通过长按后退键或摇晃手机来打开它) 在这里输入图像描述 点击“开发设置” 在调试->调试服务器主机和设备端口应该为空 注意:如果你在这里写了port或任何东西(用于调试),你应该清除它。
首先检查你的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