[ionic]解决运行Android、IOS出现Could not find the web assets directory

古城微笑少年丶 2022-09-11 08:29 93阅读 0赞

出现场景

使用Capacitor运行App时,出现以下提示。

  1. adodeMacBook-Pro:ionic_app ado$ npx cap run android
  2. copy android - failed!
  3. [error] Could not find the web assets directory: ./build.
  4. Please create it and make sure it has an index.html file. You can change
  5. the path of this directory in capacitor.config.ts (webDir option). You
  6. may need to compile the web assets for your app (typically npm run
  7. build). More info:
  8. https://capacitorjs.com/docs/basics/workflow#sync-your-project
  9. Updating Android plugins in 26.08ms
  10. update android - failed!
  11. [error] Error: ENOENT: no such file or directory, open
  12. '/Users/ado/my/work/h5/ionic_app/android/app/src/main/assets/capacitor.plugins.json'

解决方案

这是因为还没有为app编译生成web资源文件,我们先使用ionic build编译一次

  1. adodeMacBook-Pro:ionic_app ado$ ionic build
  2. > react-scripts build
  3. Creating an optimized production build...
  4. Compiled successfully.

我们可以看到项目根目录出现了一个build文件夹,说明已经编译成功。
再次运行npx cap run android或者npx cap run ios即可成功运行。

发表评论

表情:
评论列表 (有 0 条评论,93人围观)

还没有评论,来说两句吧...

相关阅读