Capacitor 5 から Capacitor 6 へのアップデート
Capacitor 5と6の間のブレークチェンジは非常に最小限になるように設計されています。このガイドでは、プロジェクトをCapacitor 6の最新バージョンにアップデートする手順と、公式プラグインの変更点を紹介します。
NodeJS 18+
Node 16は2023年9月11日をもってサポート終了となりました。Capacitor 6にはNodeJS 18以上が必要です。(最新のLTSバージョンを推奨します)。
CLIを使って移行する
プロジェクトに latest
バージョンの Capacitor CLI をインストールします:
npm i -D @capacitor/cli@latest
インストールしたら、以下を実行するだけで、CLIがマイグレーションを処理してくれます。
npx cap migrate
移行のステップのいずれかが完了できなかった場合、ターミナルの出力に追加情報が表示されます。マイグレーションを手動で行う手順を以下に示します。
VS Codeエクステンションを使って移行する
VS Codeエクステンションがインストールされている場合、エクステンションの推奨セクションをチェックするだけで、プロジェクトをCapacitor 6に移行するオプションが見つかります。
iOS
次のガイドでは、Capacitor 5 iOSプロジェクトをCapacitor 6にアップグレードする方法を説明します。
Xcodeのアップグレード
Capacitor 6にはXcode 15.0+が必要です。
SPM Support
Cocoapodsの使用からSPMへの変換はかなり大きなトピックなので、近日中に別の記 事で取り上げる予定です。
Register custom plugins
In Capacitor 6, plugin classes are no longer automatically registered. For npm installed plugins, the CLI will generate a list of plugin classes to register them programmatically. But users following the custom code guide for creating local plugins not distributed through npm, they will have to create a custom view controller and register their plugins.
Zooming
To match Android behavior, iOS apps are no longer zoomable by default. To enable zooming, check zoomEnabled
configuration option
Android
以下のガイドでは、Capacitor 5のAndroidプロジェクトをCapacitor 6にアップグレードする方法を説明します。
Android Studioのアップグレード
Capacitor 6はGradle 8.2を使用しているため、Android Studio Hedgehog | 2023.1.1以降が必要です。
アップデートが完了したら、Android Studioがgradle関連のアップデートやパッケージのビルドファイルへの移動をサポートしてくれます。 まず、Tools -> AGP Upgrade Assistant
を実行してください。
Androidプロジェクト変数の更新
variables.gradle
ファイルで、以下の新しい最小値に更新します。
minSdkVersion = 22
compileSdkVersion = 34
targetSdkVersion = 34
androidxActivityVersion = '1.8.0'
androidxAppCompatVersion = '1.6.1'
androidxCoordinatorLayoutVersion = '1.2.0'
androidxCoreVersion = '1.12.0'
androidxFragmentVersion = '1.6.2'
coreSplashScreenVersion = '1.0.1'
androidxWebkitVersion = '1.9.0'
junitVersion = '4.13.2'
androidxJunitVersion = '1.1.5'
androidxEspressoCoreVersion = '3.5.1'
cordovaAndroidVersion = '10.1.1'
google services pluginのアップデート
# build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
- classpath 'com.google.gms:google-services:4.3.15'
+ classpath 'com.google.gms:google-services:4.4.0'
gradle plugin を 8.2.1 にアップデート
# build.gradle
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
androidSchemeの更新
Capacitor 6では、Capacitorアプリケーションがシステムの Autofill機能 を利用できるようにするため、既存のアプリ__のandroidScheme
のデフォルト設定が https
になっています。
スキームを変更することは、アプリケーションを別のドメインで出荷することに等しく、Cookieやlocalstorageなどに保存されたデータにはアクセスできなくなります。この変更によるデータ損失を避けるために、Capacitorの設定ファイルに androidScheme
エントリがない場合は、スキームをhttp
に設定してください。
{
server: {
androidScheme: "http"
}
}
すでに androidScheme
エントリを https
に設定している場合は、今すぐ安全に削除できます。
kotlin versionのアップデート
プロジェクトで kotlin を使用している場合は、kotlin_version
変数を '1.9.10'
に更新してください。
プラグイン
以下のプラグイン機能が変更または削除されました。それに応じてコードを更新してください。
リスナーを持っていたすべてのプラグインについて、addListener
は Promise
を返すだけになりました。 await
を使わずに呼び出し結果を変数に格納していた場合、そのコードはコンパイルされなくなります。
Action Sheet
androidxMaterialVersion
変数が1.10.0
に更新されました。
Camera
- Capacitor Cameraプラグインのバージョン6では、Photo Picker APIを使用するようになり、
saveToGallery: true
を使用しない限り、カメラのパーミッションを宣言する必要がなくなりました。もしこれがfalseの場合、他のプラグインが以下のパーミッションを必要としなければ、AndroidManifest.xml
から削除することができます。
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- Androidで、ユーザーがギャラリーからの画像ピックをキャンセルした場合、他のプラットフォームと同様に
"User cancelled photos app"
というエラーが返されるようになりました。 - androidxMaterialVersion
変数が
1.10.0`に更新されました。
Filesystem
- iOSは他のプラットフォームと同じように、
ctime
とmtime
を文字列ではなく数値で返すようになった。
Geolocation
NSLocationAlwaysUsageDescription
(Privacy - Location Always Usage Description
) は非推奨であるため、Info.plist
から削除することができます。playServicesLocationVersion
変数が21.1.0
に更新されました。
Google Maps
- iOSのネイティブライブラリが更新されたので、詳しくはこちら をチェックしてください。
NSLocationAlwaysUsageDescription
(Privacy - Location Always Usage Description
) is deprecated and can be removed from theInfo.plist
.googleMapsPlayServicesVersion
has been updated to18.2.0
.googleMapsUtilsVersion
has been updated to3.8.2
.googleMapsKtxVersion
has been updated to5.0.0
.googleMapsUtilsKtxVersion
has been updated to5.0.0
.kotlinxCoroutinesVersion
has been updated to1.7.3
.androidxCoreKTXVersion
has been updated to1.12.0
.kotlin_version
has been updated to1.9.10
.
Local Notifications
- Android 14では、
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
パーミッションを使用 していても、通知はデフォルトでは正確ではありません。
Push Notifications
firebaseMessagingVersion
変数が23.3.1
に更新されました。
Share
androidxCoreVersion
変数が1.12.0
に更新されました。
Splash Screen
coreSplashScreenVersion
変数が1.0.1
に更新されました。
Status Bar
androidxCoreVersion
変数が1.12.0
に更新されました。