See how Capacitor fits into the entire Ionic Ecosystem ->
Capacitor is part of the Ionic Ecosystem ->

Capacitor Android プロジェクトのアップデート

アプリで使用している Capacitor のバージョンを更新したり、Android コードベース内で Capacitor とやり取りする新しい方法を使用したりするなど、Capacitor Android アプリを更新する必要があります。

Capacitor Android ライブラリのアップデート

あなたのアプリで使ってる @capacitor/android のバージョンをあげる場合、npm で最新版をインストール必要があります:

npm install @capacitor/android@latest

そして Android Studio の “Sync Project with Gradle Files” ボタンをクリックください。

Android Project のアップデート

Xcode プロジェクトのベース構造を更新するには、Capacitor リポジトリで、Capacitor の最新の安定リリースに対応するタグの下にある android-template プロジェクトを参照してください。コアプロジェクトは意図的にシンプルに保たれているため、コアプロジェクトやプロジェクトとの違いを確認するのにそれほど時間はかからないはずです。

From 1.0.0 to 1.1.0

Recommended change:

  • Update .gitignore file inside android folder with this changes

From <= 1.3.0 to 1.4.0

Recommended change:

  • Update strings.xml file inside android/app/src/main/res/values/ folder with this change

From <= 1.5.1 to 2.0.0

Mandatory change:

  • Use Android X

    Capacitor 2.0 uses Android X for Android support library dependencies as recommended by Google, so the native project needs to be updated to use Android X too.

    From Android Studio do Refactor -> Migrate to AndroidX. Then click on Migrate button and finally click on Do Refactor.

    If using Cordova or Capacitor plugins that don’t use Android X yet, you can use jetifier tool to patch them.

npm install jetifier
npx jetifier

To run it automatically after every package install, add "postinstall": "jetifier" in the package.json.

Recommended changes:

  • Create common variables

    Create a android/variables.gradle file with this content

    ext {
      minSdkVersion = 21
      compileSdkVersion = 29
      targetSdkVersion = 29
      androidxAppCompatVersion = '1.1.0'
      androidxCoreVersion =  '1.2.0'
      androidxMaterialVersion =  '1.1.0-rc02'
      androidxBrowserVersion =  '1.2.0'
      androidxLocalbroadcastmanagerVersion =  '1.0.0'
      firebaseMessagingVersion =  '20.1.2'
      playServicesLocationVersion =  '17.0.0'
      junitVersion =  '4.12'
      androidxJunitVersion =  '1.1.1'
      androidxEspressoCoreVersion =  '3.2.0'
      cordovaAndroidVersion =  '7.0.0'

    In android/build.gradle file, add apply from: "variables.gradle" as shown here.

  • Use common variables

    If you created the variables.gradle file, update your project to use them. In the android/app/build.gradle file, change:

    • compileSdkVersion 28 to compileSdkVersion rootProject.ext.compileSdkVersion
    • minSdkVersion 21 to minSdkVersion rootProject.ext.minSdkVersion
    • targetSdkVersion 28 to targetSdkVersion rootProject.ext.targetSdkVersion
    • implementation 'androidx.appcompat:appcompat:1.0.0' to implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    • testImplementation 'junit:junit:4.12' to testImplementation "junit:junit:$junitVersion"
    • androidTestImplementation 'androidx.test.ext:junit:1.1.1' to androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    • androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' to androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"

    Note that they use double quote instead of single quote now, that’s required for variables to work.

  • Android Studio Plugin Update Recommended

    When you open the Android project in Android Studio, a Plugin Update Recommended message will appear. Click on update. It will tell you to update Gradle plugin and Gradle. Click Update button.

    You can also manually update the Gradle plugin and Gradle.

    To manually update Gradle plugin, edit android/build.gradle file. Change classpath '' to classpath ''.

    To manually update Gradle, edit android/gradle/wrapper/ Change to

  • Update Google Services plugin

    In android/build.gradle file, change classpath '' to classpath ''.

  • Change configChanges to avoid app restarts

    In android/app/src/main/AndroidManifest.xml file, add |smallestScreenSize|screenLayout|uiMode in the activity android:configChanges attribute.

  • Add caches folder to FileProvider file paths to avoid permission error on editing gallery images.

    In android/app/src/main/res/xml/file_paths.xml add <cache-path name="my_cache_images" path="." />.

For API changes, check the Release Notes.

<- Configuration
Custom Native Code ->
Contribute ->