代码中的破坏性更改
插件的 success() 和 error() 方法已被删除,请改用 resolve() 和 reject()。
一些已弃用的插件定义和方法(如 registerWebPlugin)已被删除,请查看 Capacitor 3 插件升级指南以获取更多信息。
Capacitor 的辅助属性 platform 和 isNative 已被删除,请改用 getPlatform() 和 isNativePlatform() 方法。
Android
BridgeFragment 类已被删除,如果插件使用该类来呈现 Fragment,则必须创建自己的版本。
iOS
添加 SPM 支持
Capacitor 6 添加了实验性的 SPM 支持,您可以按照将现有插件转换为 SPM为您的插件 添加支持
在您的插件中将 Capacitor 更新到 7.0
使用 @capacitor/plugin-migration-v6-to-v7
从插件文件夹中,运行 npx @capacitor/plugin-migration-v6-to-v7@latest,它将自动执行所有文件更改。
手动更新文件
更新 npm 依赖项
更新 Capacitor 依赖项
将 devDependencies 中的 @capacitor/cli、@capacitor/core、@capacitor/android 和 @capacitor/ios 更新到 ^7.0.0 版本。
将 peerDependencies 中的 @capacitor/core 更新到 >=7.0.0 版本。
更新 eslint 依赖项
将 @ionic/eslint-config 更新到 ^0.4.0,将 eslint 更新到 ^8.57.0。
更新 swiftlint 依赖项
将 @ionic/swiftlint-config 和 swiftlint 更新到 ^2.0.0。
更新 prettier 依赖项
将 @ionic/prettier-config 更新到 ^4.0.0,将 prettier 更新到 ^3.4.2,将 prettier-plugin-java 更新到 ^2.6.6。
然后更新 prettier npm 脚本以添加 --plugin=prettier-plugin-java。
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
最后,您可以删除 .prettierignore 中已经在 .gitignore 中的条目,因为从 Prettier 3.0.0 开始,它默认忽略 .gitignore 文件中的文件。
如果 .prettierignore 的所有条目都已经在 .gitignore 中,则可以完全删除 .prettierignore 文件。
更新 rollup
将 rollup 更新到 ^4.30.1。然后将 rollup.config.js 文件重命名为 rollup.config.mjs。
最后,更新构建脚本以使用新的文件扩展名:
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
更新其他依赖项
将 rimraf 更新到 ^6.0.1,将 @capacitor/docgen 更新到 ^0.3.0。
更新 Android 插件变量
在您的 build.gradle 文件中,更新以下包版本最小值:
ext {
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
}
更新 targetSDK / compileSDK 到 35 和 minSDK 到 23
# build.gradle
android {
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
defaultConfig {
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
...
}
}
更新 gradle 插件到 8.7.2
dependencies {
- classpath 'com.android.tools.build:gradle:8.2.1'
+ classpath 'com.android.tools.build:gradle:8.7.2'
}
更新 gradle wrapper 到 8.11.1
# gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
更新到 Java 21
# build.gradle
compileOptions {
- sourceCompatibility JavaVersion.VERSION_17
+ sourceCompatibility JavaVersion.VERSION_21
- targetCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_21
}
更新 kotlin_version
如果您的插件使用 kotlin,请更新默认的 kotlin_version
# build.gradle
buildscript {
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.25'
repositories {
将 iOS 部署目标提高到 14
更新您的插件的 .podspec 文件
- s.ios.deployment_target = '13.0'
+ s.ios.deployment_target = '14.0'
SPM 兼容插件
更新 Package.swift 文件
- platforms: [.iOS(.v13)],
+ platforms: [.iOS(.v14)],
具有旧结构的插件
为您的 Xcode 项目执行以下操作:在项目编辑器中选择 Project 并打开 Build Settings 选项卡。在 Deployment 部分下,将 iOS Deployment Target 更改为 iOS 14.0。对任何应用 Targets 重复相同的步骤。
然后,打开 ios/Podfile 并将 iOS 版本更新到 14.0:
-platform :ios, '13.0'
+platform :ios, '14.0'