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

出现场景

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

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

解决方案

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值