跳到主要内容
版本:v6

代码中的重大变更

iOS部分

移除removeAllListeners方法

如果你的插件在.m文件中包含CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnPromise)定义,现在可以移除了,该方法已默认对所有插件可用,无需额外声明。

添加SPM支持

Capacitor 6新增了对SPM(Swift Package Manager)的试验性支持,你可以按照将现有插件转换为SPM的指南为你的插件添加支持。

definitions.ts文件变更

addListener方法的签名已修改为仅返回Promise,移除了& PluginListenerHandle联合类型。

  addListener(
eventName: 'resume',
listenerFunc: () => void,
- ): Promise<PluginListenerHandle> & PluginListenerHandle;
+ ): Promise<PluginListenerHandle>;

将插件升级至Capacitor 6.0

使用@capacitor/plugin-migration-v5-to-v6工具

在插件目录下运行npx @capacitor/plugin-migration-v5-to-v6@latest命令,该工具将自动执行所有必要的文件变更。

手动更新文件

更新package.json

@capacitor/cli@capacitor/core@capacitor/android@capacitor/ios的版本更新为latest-6

替换废弃的compileSdkVersion并更新targetSDK/compileSDK至34

# build.gradle

android {
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34

更新Gradle插件至8.2.1版本

    dependencies {
- classpath 'com.android.tools.build:gradle:8.0.0'
+ classpath 'com.android.tools.build:gradle:8.2.1'
}

更新Gradle Wrapper至8.2.1

# gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

更新Kotlin版本

如果插件使用Kotlin,请更新默认的kotlin_version配置:

# build.gradle
buildscript {
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.8.20'
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
repositories {