代码中的破坏性变化
iOS
CAPBridgedPlugin 协议的变化
CAPBridgedPlugin协议要求已从类级别移至实例级别。pluginId已重命名为identifier,以避免与CAPPlugin.pluginId冲突,并且getMethod(_:)要求已被完全移除并放入内部扩展方法中。pluginMethods也已更新,以更具体地说明其内容(之前是Any,现在是CAPPluginMethod)。
绝大多数用户应该不会遇到任何问题,因为当前的做法是使用宏来生成对 CAPBridgedPlugin 的遵循。任何将对象强制转换为 CAPBridgedPlugin 或手动遵循 CAPBridgedPlugin 而未使用宏的用户将受到影响。
Android
PluginCall.getObject() / PluginCall.getArray()
为了匹配 iOS 的行为,Android 上的 PluginCall.getObject() 和 PluginCall.getArray() 现在可以返回 null。我们建议插件作者在这两种方法的返回处理代码周围执行空值检查。
在您的插件中将 Capacitor 更新到 5.0
使用 @capacitor/plugin-migration-v4-to-v5
在插件文件夹中运行 npx @capacitor/plugin-migration-v4-to-v5@latest,它将自动执行所有文件更改。
手动更新文件
更新 package.json
将 @capacitor/cli、@capacitor/core、@capacitor/android 和 @capacitor/ios 更新到 latest-5 版本。
更新 targetSDK / compileSDK 到 33
# build.gradle
android {
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
更新 Android 插件变量
在您的 build.gradle 文件中,更新以下包版本的最低要求:
ext {
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
更新 gradle 插件到 8.0.0
dependencies {
- classpath 'com.android.tools.build:gradle:7.2.1'
+ classpath 'com.android.tools.build:gradle:8.0.0'
}