メインコンテンツにジャンプします。
Capacitor

Updating from Capacitor 4 to Capacitor 5: A Step-by-Step Guide

Learn how to update your project from Capacitor 4 to Capacitor 5 with minimal breaking changes, including updating official plugins and required tools.

著者

マーティン・ドナディュー

ライター

バレリア

レビュー

ジョーダン

編集者

Updating from Capacitor 4 to Capacitor 5: A Step-by-Step Guide

Compared to previous updates, the transition from Capacitor 4 to Capacitor 5 involves minimal breaking changes. This guide provides step-by-step instructions for updating your project to Capacitor 5, as well as a list of breaking changes for official plugins.

注記Capacitor 5 は、NodeJS 16 以上が必要です。Node 12 はすでにサポート終了しており、Node 14 は 2023 年 4 月 30 日にサポート終了予定です。最新の LTS バージョンの NodeJS を使用することをお勧めします。

  1. Capacitor 5をインストールします。 latest Capacitor 5 の Capacitor CLI をプロジェクト内で更新する

    npm i -D @capacitor/cli@latest
  2. Capacitor 5 にアップグレードするには、以下のコマンドを実行して、CLI がマイグレーションを管理するようにします。

    npx cap migrate

    アップグレードの際に、migrationステップのいくつかが実行できない場合、ターミナル出力に追加情報が提供されます。 以下に手動でのmigrationステップが記載されています。

  3. Capacitor 4からCapacitor 5にアップデートする場合、Visual Studio の Code 拡張機能がインストールされている場合は、拡張機能の推奨事項セクションでプロジェクトを Capacitor 5に移行するオプションを確認してください。

Upgrading Capacitor 4 iOS Project to Capacitor 5

  1. アップグレード Xcode: Capacitor 5 requires Xcode 14.1+.

  2. Capacitor 5 へのアップデート: __CAPGO_KEEP_0__ から __CAPGO_KEEP_1__ へのアップグレードを行ってください。 .gitignore : ファイルを更新してください。

    - App/Podfile.lock
    + App/output
  3. Update Assets を使用して、単一のアプリアイコンを使用するように変更してください。コンテキスト: 解決策 ページのアプリ例のセクション。役割: 画像の代替テキスト。見られる場所: コンポーネント解決策/ SolutionAppExample.astro。メッセージキー `solution_app_examples_icon_alt` (Solution App Examples Icon Alt)。

Upgrading Capacitor 4 Android Project to Capacitor 5

  1. __CAPGO_KEEP_0__ 4 Android Project を __CAPGO_KEEP_1__ 5 にアップグレードする: Capacitor 5 requires Android Studio Flamingo | 2022.2.1 or newer due to the usage of Gradle 8, which requires Java JDK 17. Java 17 ships with Android Studio Flamingo, so no additional downloads are needed.

  2. : __CAPGO_KEEP_0__ 5 では、Gradle 8 の使用により、Java JDK 17 が必要です。Java 17 は Android Studio Flamingo に含まれているため、追加のダウンロードは必要ありません。AGP Upgrade Assistant を実行してください。 Tools -> AGP Upgrade Assistant.

  3. : Android Studio は、Gradle とパッケージをビルドファイルに移動する関連する更新を助けることができます。始めるには、Android Project Variables を更新してください。 variables.gradle : ご自身のファイルを更新してください。値を、以下の新しい最小値に更新してください。

    minSdkVersion = 22
    compileSdkVersion = 33
    targetSdkVersion = 33
    androidxActivityVersion = '1.7.0'
    androidxAppCompatVersion = '1.6.1'
    androidxCoordinatorLayoutVersion = '1.2.0'
    androidxCoreVersion = '1.10.0'
    androidxFragmentVersion = '1.5.6'
    coreSplashScreenVersion = '1.0.0'
    androidxWebkitVersion = '1.6.1'
    junitVersion = '4.13.2'
    androidxJunitVersion = '1.1.5'
    androidxEspressoCoreVersion = '3.5.1'
    cordovaAndroidVersion = '10.1.1'
  4. アップデート Google Services:

    # build.gradle
    dependencies {
    -       classpath 'com.google.gms:google-services:4.3.13'
    +       classpath 'com.google.gms:google-services:4.3.15'
    }
  5. Gradle プラグインを 8.0.0 にアップデート:

    # build.gradle
    dependencies {
    -       classpath 'com.android.tools.build:gradle:7.2.1'
    +       classpath 'com.android.tools.build:gradle:8.0.0'
    }
  6. Gradle ラッパーを 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
  7. Jetifier を無効化:

    # gradle.properties
    android.useAndroidX=true
    - android.enableJetifier=true
  8. パッケージを移動 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 rootProject.ext.compileSdkVersion
  9. androidScheme をアップデート: Capacitor 6 については、 https のデフォルト設定になります。既存のアプリケーションでは、__CAPGO_KEEP_0__ アプリケーションがシステムの Autofill 機能を使用できるようにするために、 androidScheme for existing apps to better enable Capacitor applications to use the system Autofill feature. To avoid data loss as a result of this change, set the scheme to http を設定してください。

    {
      server: {
        androidScheme: "http"
      }
    }
  10. Kotlin バージョンをアップデート: Kotlin を使用するプロジェクトでは、 kotlin_version 変数を '1.8.20'.

プラグイン機能の変更

以下のプラグイン機能が変更または削除されました。codeを更新してください。

  • アクションシート
  • ブラウザ
  • カメラ
  • デバイス
  • 位置情報
  • Google マップ
  • ローカル通知
  • プッシュ通知
  • ステータスバー

アクション シート

  • アップデート androidxMaterialVersion 変数を 1.8.0.

ブラウザ

  • アップデート androidxBrowserVersion 変数を 1.5.0.

カメラ

  • Android 13 の場合、読み取り用メディア イメージの権限を追加してください (<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>の内側に AndroidManifest.xml.
  • アップデート androidxMaterialVersion 変数を 1.8.0.
  • アップデート androidxExifInterfaceVersion 変数を 1.3.6.

デバイス

  • 変更 DeviceId.uuidDeviceId.identifier.
  • iOS 16+ では、 DeviceInfo.name 適切な特権を追加しない限り、一般的なデバイス名が返されます。 位置情報.

更新

  • playServicesLocationVersion Google マップ 21.0.1.

以下の変数を更新してください:

  • __CAPGO_KEEP_0__
    • googleMapsPlayServicesVersion18.1.0.
    • googleMapsUtilsVersion3.4.0.
    • googleMapsKtxVersion3.4.0.
    • googleMapsUtilsKtxVersion3.4.0.
    • kotlinxCoroutinesVersion1.6.4.
    • androidxCoreKTXVersion1.10.0.
    • kotlin_version ローカル通知 1.8.20.

Android 13では、ローカル通知をスケジュールするために必要な新しいランタイムパーミッションチェックが実行されます。__CAPGO_KEEP_0__ 33をターゲットにすると、

  • For Android 13, a new runtime permission check is required to schedule local notifications when targeting SDK 33. Call checkPermissions() したがって。 requestPermissions() プッシュ通知

Android 13では、プッシュ通知の機能が削除されました。代わりに、ローカル通知を使用してユーザーに通知を送信する必要があります。

  • Android 13では、SDK 33. Callに対してプッシュ通知を受け取るために必要な新しい実行時許可チェックが必要です。 checkPermissions()requestPermissions() したがって。
  • を更新する firebaseMessagingVersion23.1.2.

ステータスバー

  • iOSでは、デフォルトのステータスバーのアニメーションが変更されました。 FADE.

これらのステップに従い、code を更新すると、Capacitor 4からCapacitor 5にプロジェクトを更新することができました。すべての機能とプラグインが期待どおりに動作することを確認するために、必ずアプリケーションを徹底的にテストしてください。

Updating from Capacitor 4 to Capacitor 5: A Step-by-Step Guide

Capacitor 4を使用している場合 Updating from Capacitor 4 to Capacitor 5: A Step-by-Step Guide nativeプラグインの作業を計画するには、__CAPGO_KEEP_0__ を接続する必要があります Capgo プラグイン ディレクトリ for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, プラグインの追加または更新 プラグインの追加または更新 イオニック エンタープライズ プラグインの代替 Capacitor 4 から Capacitor 5 へのアップデート Capgo Native Builds for the product workflow in Capgo Native Builds.

Live updates for Capacitor apps

When a web-layer bug is live, ship the fix through Capgo instead of waiting days for app store approval. Users get the update in the background while native changes stay in the normal review path.

マーティンによる人間のサポート

今すぐ始めよう

最新のブログ記事

Capgoは、プロフェッショナルなモバイルアプリを作成するために必要な最良の洞察を提供します。