Ionic 5 Android SDK leve 31 or later

Hello,
My current versions are:
Ionic:

Ionic CLI : 6.20.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.6.11
@angular-devkit/build-angular : 12.0.5
@angular-devkit/schematics : 12.1.1
@angular/cli : 12.0.5
@ionic/angular-toolkit : 4.0.0

Capacitor:

Capacitor CLI : 3.1.1
@capacitor/android : 3.1.2
@capacitor/core : 3.1.1
@capacitor/ios : 3.1.1

Utility:

cordova-res : 0.15.4
native-run (update available: 1.7.2) : 1.4.0

System:

NodeJS : v18.15.0 (/usr/local/bin/node)
npm : 9.5.0
OS : macOS Big Sur

How may I build Android SDK level 31? Only updating Capacitor (3 to 4)?
I tried to update Capacitor (3 to 4) (npm i -D @capacitor/cli@latest and npx cap migrate) but my project stopped work.
After update Capacitor, which changes are need in my project?
Does anyone know a tutorial to share?

Yeah, you have to migrate to Capacitor 4.
What’s the error you get once you migrate?

After update Capacitor, when I run it the browser shows “Cannot GET”.

Copy your shell output, otherwise we can’t understand what is going on

I tried again (npm i -D @capacitor/cli@latest and npx cap migrate).
These were the errors:

:heavy_multiplication_x: Upgrading gradle wrapper files - failed!
[error] gradle wrapper files were not updated
[info] IMPORTANT: Review Updating to 4.0 | Capacitor Documentation for breaking changes in these plugins that
you use: @capacitor/storage.
[info] Warning: The Android Gradle plugin was updated and it requires Java 11 to run. You may need to select this in
Android Studio.

:heavy_multiplication_x: Installing Latest NPM Modules. - failed!
[error] npm install failed. Try deleting node_modules folder and running npm install --force manually.
[info] NOTE: @capacitor/storage was renamed to @capacitor/preferences, please be sure to replace occurances in your
code.

:heavy_multiplication_x: Migrating @capacitor/storage to @capacitor/preferences. - failed!
[error] @capacitor/preferences failed to install. Try deleting node_modules folder and running npm install
@capacitor/preferences --force manually.

Thus, I followed this steps:

  1. delete package-lock.json file.
  2. package.json file has been changed: “capacitor-video-player”: “^4.6.2-3”,
  3. storage.services file has been changed :

import { Preferences } from ‘@capacitor/preferences’;

async setString(key: string, value: string) {
await Preferences.set({ key, value });
}

It was: import { Storage } from ‘@capacitor/storage’; …

  1. The steps listed on the site (Updating to 4.0 | Capacitor Documentation) for Android already were correct (-Using Java 11, -Add android:exported tag to your Android Manifest, -Update Gradle Google Services plugin, -Update to Gradle), except: Update Android Project Variables
    Thus, variables.gradle file has been updated.

After this steps, Android Studio (Build, Generate Signed Bundle / APK) built SDK level 32.