跳过内容

重大变更

本文档解释了如何使用版本通道来处理应用程序中的破坏性更改。这一方法允许您维护应用程序的不同版本,同时确保用户接收兼容的更新。

假设您有:

  • App 版本 1.2.3 (旧版本) - 使用生产频道
  • App 版本 2.0.0 (新版本,包含重大更改) - 使用 v2 频道
  • 实时更新 1.2.4 (兼容 1.2.3)
  • 实时更新 2.0.1 (兼容 2.0.0)

策略:Always 使用 defaultChannel 为主要版本

标题:策略:Always 使用 defaultChannel 为主要版本

推荐方法: 为每个主要版本设置一个 defaultChannel 。这样您就可以始终将更新推送到特定用户组,而不依赖于动态频道分配。

// Version 1.x releases
defaultChannel: 'v1'
// Version 2.x releases
defaultChannel: 'v2'
// Version 3.x releases (future)
defaultChannel: 'v3'

标题为“1. 为新版本创建频道”

终端窗口
在应用中 __CAPGO_KEEP_0__
# Create channel for version 2.x
npx @capgo/cli channel create v2

2. 为版本 2.0.0 更新 Capacitor 配置

标题:2. 为版本 2.0.0 更新 Capacitor 配置

在发布应用商店版本 2.0.0 之前,请更新您的 Capacitor 配置:

capacitor.config.ts
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'Example App',
plugins: {
CapacitorUpdater: {
// ... other options
defaultChannel: 'v2' // All 2.0.0 users will use v2 channel
}
}
};
export default config;

3. 单独管理 Code 分支

标题:3. 单独管理 Code 分支

为保持应用程序版本之间的兼容性,创建单独的 Git 分支:

终端窗口
# Create and maintain a branch for version 1.x updates
git checkout -b v1-maintenance
git push origin v1-maintenance
# Your main branch continues with version 2.x development
git checkout main

重要提示: 永远不要将 JavaScript 包推送到不支持 code/API 的旧应用中。始终从适当的分支中构建更新:

  • v1-maintenance branch: 对 1.x 应用程序的更新(生产频道)
  • main branch: 对 2.x 应用程序的更新(v2 频道)

4. 将捆绑包上传到各个渠道

第 4 步:将捆绑包上传到各个渠道
终端窗口
# For 1.x updates: Build from v1-maintenance branch
git checkout v1-maintenance
# Make your 1.x compatible changes here
npx @capgo/cli bundle upload --channel production
# For 2.x updates: Build from main branch
git checkout main
# Make your 2.x changes here
npx @capgo/cli bundle upload --channel v2

5. 启用自我分配

第 5 步:启用自我分配
终端窗口
# Allow apps to self-assign to v2 channel
npx @capgo/cli channel set v2 --self-assign

注意

适应未来的版本

标题:适应未来的版本

当您发布3.0.0版本时,带有更多破坏性更改:

终端窗口
# Create channel for version 3.x
npx @capgo/cli channel create v3
// capacitor.config.ts for version 3.0.0
const config: CapacitorConfig = {
// ...
plugins: {
CapacitorUpdater: {
defaultChannel: 'v3' // Version 3.x users
}
}
};

现在您可以推送任何版本的更新:

  • production 频道 → 版本1.x的用户
  • v2 频道 → 2.x 版本用户
  • v3 频道 → 3.x 版本用户

7. 清理(迁移后)

迁移后清理(第 7 步)

所有用户迁移到 2.x 版本后(大约 3-4 个月):

  1. 移除 defaultChannel 从您的 Capacitor 配置中
  2. 删除 v2 频道:
终端窗口
npx @capgo/cli channel delete v2
  1. 删除 v1-maintenance Branch:
终端窗口
git branch -d v1-maintenance
git push origin --delete v1-maintenance

始终在每个渠道中彻底测试更新之前部署

维护 1.x 版本更新

标题:维护 1.x 版本更新

要发送与 1.x 版本兼容的更新,请执行以下操作:

  1. 切换到 v1-maintenance Branch:
终端窗口
git checkout v1-maintenance
  1. 请修改并提交:
终端窗口
# Make 1.x compatible changes
git add .
git commit -m "Fix for v1.x"
git push origin v1-maintenance
  1. 构建并上传到生产频道:
终端窗口
npx @capgo/cli bundle upload --channel production