跳到主要内容
版本:v8

代码中的破坏性更改

iOS

删除 removeAllListeners 方法

如果您的插件在 .m 文件中有 CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnPromise),现在可以删除它,该方法现在可用于所有插件而无需定义它。

添加 SPM 支持

Capacitor 6 添加了实验性的 SPM 支持,您可以按照将现有插件转换为 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_version

如果您的插件使用 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 {