代码中的重大变更
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。我们建议插件作者在处理这些方法返回值的代码周围执行 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'
}
将 gradle wrapper 更新至 8.0.2
# gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
将包声明移至 build.gradle
# AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="[YOUR_PACKAGE_ID]">
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
# build.gradle
android {
+ namespace "[YOUR_PACKAGE_ID]"
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
禁用 Jetifier
# gradle.properties
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
- # Automatically convert third-party libraries to use AndroidX
- android.enableJetifier=true
更新至 Java 17
# build.gradle
compileOptions {
- sourceCompatibility JavaVersion.VERSION_11
+ sourceCompatibility JavaVersion.VERSION_17
- targetCompatibility JavaVersion.VERSION_11
+ targetCompatibility JavaVersion.VERSION_17
}
更新 kotlin_version
如果你的插件使用了 kotlin,请更新默认的 kotlin_version
# build.gradle
buildscript {
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.7.0'
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.8.20'
repositories {
并将 org.jetbrains.kotlin:kotlin-stdlib-jdk7 或 org.jetbrains.kotlin:kotlin-stdlib-jdk8 依赖项替换为 org.jetbrains.kotlin:kotlin-stdlib。
# build.gradle
dependencies {
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"