capacitor-app-upgrade-v4-to-v5

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Capacitor App Upgrade v4 to v5

Capacitor 应用从v4升级到v5

Upgrade a Capacitor app from version 4 to version 5.
将Capacitor应用从版本4升级到版本5。

When to Use This Skill

何时使用本技能

  • User says the app is on Capacitor 4 and must move to v5
  • User wants the exact v4 to v5 migration path
  • User needs v5-specific native and package updates
  • 用户表明应用基于Capacitor 4开发,必须升级到v5
  • 用户需要v4到v5的准确迁移路径
  • 用户需要v5专属的原生端及包更新内容

Live Project Snapshot

项目实时快照

Current Capacitor packages from
package.json
: !
node -e "const fs=require('fs');if(!fs.existsSync('package.json'))process.exit(0);const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const out=[];for(const section of ['dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(name.startsWith('@capacitor/'))out.push(section+'.'+name+'='+version)}}console.log(out.sort().join('\n'))"
package.json
中读取当前Capacitor相关包: !
node -e "const fs=require('fs');if(!fs.existsSync('package.json'))process.exit(0);const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const out=[];for(const section of ['dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(name.startsWith('@capacitor/'))out.push(section+'.'+name+'='+version)}}console.log(out.sort().join('\n'))"

Procedure

操作步骤

  1. Start from the injected package snapshot and confirm the current
    @capacitor/core
    version.
  2. Update all
    @capacitor/*
    packages to the v5-compatible range.
  3. Review the v4 to v5 migration notes before editing native files.
  4. Run
    npm install
    .
  5. Sync with
    npx cap sync
    .
  6. Verify the iOS and Android builds.
  1. 基于注入的包快照确认当前
    @capacitor/core
    版本。
  2. 将所有
    @capacitor/*
    包更新到v5兼容的版本范围。
  3. 在编辑原生文件前查阅v4到v5的迁移说明。
  4. 运行
    npm install
  5. 执行
    npx cap sync
    同步资源。
  6. 验证iOS和Android构建是否正常。

Error Handling

错误处理

  • If the automated migration misses a package, update it manually before syncing again.
  • If iOS fails, check the deployment target and Xcode compatibility for Capacitor 5.
  • If Android fails, check the Gradle and Java requirements for Capacitor 5.
  • 如果自动迁移遗漏了某个包,请先手动更新再重新同步。
  • 如果iOS构建失败,请检查Capacitor 5要求的部署目标版本和Xcode兼容性。
  • 如果Android构建失败,请检查Capacitor 5要求的Gradle和Java版本要求。