capacitor-app-migrations
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCapacitor App Migration
Capacitor应用迁移
Migrate a Capacitor app project to a newer major version (4→5, 5→6, 6→7, or 7→8).
将Capacitor应用项目迁移至更新的主版本(4→5、5→6、6→7或7→8)。
Prerequisites
前置要求
| Target Version | Node.js | Xcode | Android Studio |
|---|---|---|---|
| 5 | 16+ | 14.1+ | Flamingo 2022.2.1+ (Java 17) |
| 6 | 18+ | 15.0+ | Hedgehog 2023.1.1+ |
| 7 | 20+ | 16.0+ | Ladybug 2024.2.1+ (Java 21) |
| 8 | 22+ | 26.0+ | Otter 2025.2.1+ |
| 目标版本 | Node.js | Xcode | Android Studio |
|---|---|---|---|
| 5 | 16+ | 14.1+ | Flamingo 2022.2.1+(Java 17) |
| 6 | 18+ | 15.0+ | Hedgehog 2023.1.1+ |
| 7 | 20+ | 16.0+ | Ladybug 2024.2.1+(Java 21) |
| 8 | 22+ | 26.0+ | Otter 2025.2.1+ |
Procedures
迁移步骤
Step 1: Detect Current Version
步骤1:检测当前版本
Read version from ( or ). Determine the current major version.
@capacitor/corepackage.jsondependenciesdevDependenciesAsk the user for the target version. Default to the latest (8) if not specified.
从的或中读取的版本,确定当前主版本。
package.jsondependenciesdevDependencies@capacitor/core向用户询问目标版本,若未指定则默认使用最新版本(8)。
Step 2: Execute Migration
步骤2:执行迁移
For each major version jump between the current and target version, apply the corresponding migration guide sequentially:
| Current → Target | Reference |
|---|---|
| 4 → 5 | |
| 5 → 6 | |
| 6 → 7 | |
| 7 → 8 | |
For multi-version jumps (e.g., 5 → 8), apply each migration in order:
- Read and apply
references/migration-v5-to-v6.md - Run , build, and verify on both platforms
npx cap sync - Read and apply
references/migration-v6-to-v7.md - Run , build, and verify on both platforms
npx cap sync - Read and apply
references/migration-v7-to-v8.md - Run , build, and verify on both platforms
npx cap sync
Do not skip intermediate versions.
对于当前版本与目标版本之间的每一次主版本升级,需按顺序应用对应的迁移指南:
| 当前版本→目标版本 | 参考文档 |
|---|---|
| 4 → 5 | |
| 5 → 6 | |
| 6 → 7 | |
| 7 → 8 | |
对于跨版本跳跃迁移(例如5→8),需按顺序完成每一步迁移:
- 阅读并应用中的内容
references/migration-v5-to-v6.md - 运行,在两个平台上构建并验证
npx cap sync - 阅读并应用中的内容
references/migration-v6-to-v7.md - 运行,在两个平台上构建并验证
npx cap sync - 阅读并应用中的内容
references/migration-v7-to-v8.md - 运行,在两个平台上构建并验证
npx cap sync
请勿跳过中间版本。
Step 3: Final Verification
步骤3:最终验证
After completing all migration steps:
bash
npx cap sync
npx cap run android
npx cap run ios完成所有迁移步骤后:
bash
npx cap sync
npx cap run android
npx cap run iosError Handling
错误处理
- If fails partially, check the terminal output for which steps failed and apply those manually using the steps in the corresponding reference file.
npx cap migrate - If Android build fails after migration, run Tools > AGP Upgrade Assistant in Android Studio.
- If iOS build fails, verify the deployment target matches the target version requirements in the reference file.
- If Gradle property syntax warnings appear (v8+), search all files for property assignments without
.gradleand update them.= - If a multi-version migration fails mid-way, fix the current version step before proceeding to the next.
- 如果部分执行失败,请查看终端输出确认哪些步骤失败,并使用对应参考文件中的步骤手动完成这些操作。
npx cap migrate - 如果迁移后Android构建失败,请在Android Studio中运行Tools > AGP Upgrade Assistant(AGP升级助手)。
- 如果iOS构建失败,请确认部署目标与参考文件中目标版本的要求匹配。
- 如果出现Gradle属性语法警告(v8及以上版本),请搜索所有文件,找到没有使用
.gradle的属性赋值并更新。= - 如果跨版本迁移中途失败,请先修复当前版本的问题,再继续进行下一个版本的迁移。