Updating Your Capacitor Android Project
Occasionally, you'll need to make Capacitor updates to your Android app, including updating the version of Capacitor used in your app, or using new ways of interfacing with Capacitor inside of your Android codebase.
Updating Capacitor Android Library
To update the version of @capacitor/android used in your app, just npm install latest version:
npm install @capacitor/android@2
Then from Android Studio click the "Sync Project with Gradle Files" button.
Updating Android Project
To update the base structure of your Android project, view the android-template project in the Capacitor repo, under the tag corresponding to the latest stable release of Capacitor. The core project is kept simple on purpose: it shouldn't take much time to see what is different from the core project and your project.
From 1.0.0 to 1.1.0
Recommended change:
- Update .gitignorefile insideandroidfolder with this changes
From <= 1.3.0 to 1.4.0
Recommended change:
- Update strings.xmlfile insideandroid/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- Migratebutton 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 -D jetifier
npx jetifier
To run it automatically after every package install, add "postinstall": "jetifier" in the package.json under "scripts".
Recommended changes:
- Create common variables - Create a - android/variables.gradlefile 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.gradlefile, add- apply from: "variables.gradle"as shown here.
- Use common variables - If you created the - variables.gradlefile, update your project to use them. In the- android/app/build.gradlefile, change:- compileSdkVersion 28to- compileSdkVersion rootProject.ext.compileSdkVersion
- minSdkVersion 21to- minSdkVersion rootProject.ext.minSdkVersion
- targetSdkVersion 28to- 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 Recommendedmessage will appear. Click on- update. It will tell you to update Gradle plugin and Gradle. Click- Updatebutton.- You can also manually update the Gradle plugin and Gradle. - To manually update Gradle plugin, edit - android/build.gradlefile. Change- classpath 'com.android.tools.build:gradle:3.3.2'to- classpath 'com.android.tools.build:gradle:3.6.1'.- To manually update Gradle, edit - android/gradle/wrapper/gradle-wrapper.properties. Change- gradle-4.10.1-all.zipto- gradle-5.6.4-all.zip.
- Update Google Services plugin - In - android/build.gradlefile, change- classpath 'com.google.gms:google-services:4.2.0'to- classpath 'com.google.gms:google-services:4.3.3'.
- Change configChanges to avoid app restarts - In - android/app/src/main/AndroidManifest.xmlfile, add- |smallestScreenSize|screenLayout|uiModein the activity- android:configChangesattribute.
- Add caches folder to FileProvider file paths to avoid permission error on editing gallery images. - In - android/app/src/main/res/xml/file_paths.xmladd- <cache-path name="my_cache_images" path="." />.
For API changes, check the Release Notes.