capacitor-plugin-upgrade-v4-to-v5

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Capacitor Plugin Upgrade v4 to v5

Capacitor 插件 v4 至 v5 升级指南

Upgrade a Capacitor plugin from version 4 to version 5.
将Capacitor插件从版本4升级到版本5。

When to Use This Skill

何时使用本技能

  • User says the plugin targets 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

项目快照获取

Plugin and Capacitor package snapshot: !
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=['package.name='+(pkg.name||''),'package.version='+(pkg.version||'')];for(const section of ['peerDependencies','dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(name.startsWith('@capacitor/'))out.push(section+'.'+name+'='+version)}}console.log(out.join('\n'))"
Example and native project paths: !
find . -maxdepth 3 \( -path './example-app' -o -path './ios' -o -path './android' \)
插件与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=['package.name='+(pkg.name||''),'package.version='+(pkg.version||'')];for(const section of ['peerDependencies','dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(name.startsWith('@capacitor/'))out.push(section+'.'+name+'='+version)}}console.log(out.join('\n'))"
示例与原生项目路径: !
find . -maxdepth 3 \( -path './example-app' -o -path './ios' -o -path './android' \)

Procedure

操作步骤

  1. Start from the injected snapshot and confirm the current Capacitor peer dependency range in
    package.json
    .
  2. Update the peer dependency range to Capacitor 5.
  3. Review the v4 to v5 migration notes before editing native files.
  4. Update the example app if it exists.
  5. Run
    npm install
    .
  6. Sync and verify the example or test app.
  1. 基于注入的项目快照,确认
    package.json
    中当前Capacitor peer依赖的版本范围
  2. 将peer依赖的版本范围更新为支持Capacitor 5
  3. 编辑原生文件前先查阅v4到v5的迁移说明
  4. 若存在示例应用,对其进行更新
  5. 运行
    npm install
  6. 同步并验证示例或测试应用

Error Handling

错误处理

  • If the example app breaks, fix the plugin API or native bridge before moving on.
  • If iOS fails, verify the deployment target for Capacitor 5.
  • If Android fails, verify the Gradle and Java requirements for Capacitor 5.
  • 若示例应用运行异常,先修复插件API或原生桥接逻辑再继续后续操作
  • 若iOS端运行失败,验证Capacitor 5要求的部署目标版本
  • 若Android端运行失败,验证Capacitor 5要求的Gradle和Java版本配置