OGeek|极客世界-中国程序员成长平台

标题: android - 无法从 Windows 上的 Assets index.android.bundle 加载脚本 [打印本页]

作者: 菜鸟教程小白    时间: 2022-8-1 01:19
标题: android - 无法从 Windows 上的 Assets index.android.bundle 加载脚本

我正在尝试第一次在我的设备(Android 4.2.2)上运行我的第一个 React Native 项目。

我得到:

unable to load script from assets index.android.bundle



我使用的命令:
  • cd (project directory)
  • react-native start
  • react-native run-android


  • Best Answer-推荐答案


    我在关注 React Native tutorial 时遇到了同样的问题(在 Linux 上开发并针对 Android)。

    这个issue帮助我通过以下步骤解决问题。

  • (在项目目录中)mkdir 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
  • react-native run-android

  • 您可以通过将它们放在 scripts 中自动执行上述步骤。 package.json 的一部分像这样:
    "android-linux": "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"
    

    然后你可以执行npm run android-linux每次从你的命令行。

    关于android - 无法从 Windows 上的 Assets index.android.bundle 加载脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44446523/






    欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4