Capacitor 5升级至6时CLI迁移失败,遇npm安装及图标问题
解决Capacitor 5 升级至 6 CLI迁移异常问题
迁移时遇到的异常信息
✖ Installing Latest Modules using npm. - failed! [error] npm install failed. Try deleting node_modules folder and running npm install --force manually. [error] Unable to find AppIcon-512@2x.png. Try updating it manually ✔ Update App Icon to only 1024 x 1024 in 391.79μs ✔ Remove Podfile.lock from iOS .gitignore in 331.92μs ✔ Migrating build.gradle file. in 6.71ms ✔ Remove android.enableJetifier=true from gradle.properties in 363.96μs [error] Found namespace in build.gradle already, skipping migration ✔ Migrating package from Manifest to build.gradle in 460.83μs ✔ Migrating gradle-wrapper.properties by updating gradle version to 8.0.2. in 479.67μs ✔ Migrating variables.gradle file. in 2.82ms [warn] Skipped migrating package from Manifest to build.gradle in Capacitor plugins [warn] Skipped Running cap sync. [warn] Skipped upgrading gradle wrapper files ✔ Writing breaking changes. in 125.63μs [warn] Migration to Capacitor ^5.0.0 is incomplete. Check the log messages for more information.
分步解决方案
修复npm安装失败
- 删除项目根目录下的
node_modules文件夹和package-lock.json文件 - 执行命令:
npm install --force - 若仍失败,检查
package.json中Capacitor相关依赖(如@capacitor/core、@capacitor/android、@capacitor/ios)是否已指定^6.x.x版本,手动调整后重新执行安装
- 删除项目根目录下的
修复AppIcon缺失问题
- 找到iOS项目的
Assets.xcassets/AppIcon.appiconset目录 - 确认是否存在
AppIcon-512@2x.png(要求尺寸为1024x1024),缺失则生成对应图标放入该目录 - 执行命令:
cap sync ios同步图标配置
- 找到iOS项目的
处理build.gradle namespace提示
该提示为正常情况,说明Android项目的android/app/build.gradle中已配置namespace字段,无需额外操作,可自行核对字段值是否匹配应用包名完成剩余迁移步骤
- 重新执行迁移命令:
npx @capacitor/cli migrate - 执行全平台同步:
cap sync - 检查Android项目
gradle/wrapper/gradle-wrapper.properties中的distributionUrl是否已更新至gradle 8.0.2版本,未更新则手动调整
- 重新执行迁移命令:
内容的提问来源于stack exchange,提问作者Xero
相关产品推荐
相关产品推荐

