capacitor-app-migrations

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Capacitor 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 VersionNode.jsXcodeAndroid Studio
516+14.1+Flamingo 2022.2.1+ (Java 17)
618+15.0+Hedgehog 2023.1.1+
720+16.0+Ladybug 2024.2.1+ (Java 21)
822+26.0+Otter 2025.2.1+
目标版本Node.jsXcodeAndroid Studio
516+14.1+Flamingo 2022.2.1+(Java 17)
618+15.0+Hedgehog 2023.1.1+
720+16.0+Ladybug 2024.2.1+(Java 21)
822+26.0+Otter 2025.2.1+

Procedures

迁移步骤

Step 1: Detect Current Version

步骤1:检测当前版本

Read
@capacitor/core
version from
package.json
(
dependencies
or
devDependencies
). Determine the current major version.
Ask the user for the target version. Default to the latest (8) if not specified.
package.json
dependencies
devDependencies
中读取
@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 → TargetReference
4 → 5
references/migration-v4-to-v5.md
5 → 6
references/migration-v5-to-v6.md
6 → 7
references/migration-v6-to-v7.md
7 → 8
references/migration-v7-to-v8.md
For multi-version jumps (e.g., 5 → 8), apply each migration in order:
  1. Read and apply
    references/migration-v5-to-v6.md
  2. Run
    npx cap sync
    , build, and verify on both platforms
  3. Read and apply
    references/migration-v6-to-v7.md
  4. Run
    npx cap sync
    , build, and verify on both platforms
  5. Read and apply
    references/migration-v7-to-v8.md
  6. Run
    npx cap sync
    , build, and verify on both platforms
Do not skip intermediate versions.
对于当前版本与目标版本之间的每一次主版本升级,需按顺序应用对应的迁移指南:
当前版本→目标版本参考文档
4 → 5
references/migration-v4-to-v5.md
5 → 6
references/migration-v5-to-v6.md
6 → 7
references/migration-v6-to-v7.md
7 → 8
references/migration-v7-to-v8.md
对于跨版本跳跃迁移(例如5→8),需按顺序完成每一步迁移:
  1. 阅读并应用
    references/migration-v5-to-v6.md
    中的内容
  2. 运行
    npx cap sync
    ,在两个平台上构建并验证
  3. 阅读并应用
    references/migration-v6-to-v7.md
    中的内容
  4. 运行
    npx cap sync
    ,在两个平台上构建并验证
  5. 阅读并应用
    references/migration-v7-to-v8.md
    中的内容
  6. 运行
    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 ios

Error Handling

错误处理

  • If
    npx cap migrate
    fails partially, check the terminal output for which steps failed and apply those manually using the steps in the corresponding reference file.
  • 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
    .gradle
    files for property assignments without
    =
    and 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
    文件,找到没有使用
    =
    的属性赋值并更新。
  • 如果跨版本迁移中途失败,请先修复当前版本的问题,再继续进行下一个版本的迁移。