Updating from Capacitor 3 to Capacitor 4 updated_at: 2024-12-16 03:41

Updating from Capacitor 3 to Capacitor 4

사용중에 이런 에러 메시지를 만난다면 capacitor 를 업데이트 하여야 한다.

참조

Your app currently targets API level 30 and must target at least API level 31 to ensure it is built on the latest APIs optimized for security and performance. Change your app's target API level to at least 31. Learn More

현재 버젼 확인

npx cap --version  // 현재 버젼 확인
3.5.1

Using the CLI to Migrate

Step 1

npm i -D @capacitor/cli@latest-4

아래와 같이 버젼이 업데이트 된 것을 확인 할 수 있습니다.

npx cap --version
4.8.0

Step 2

npx cap migrate

위의 명령을 입력후 아래는 일련의 과정이다.

PS D:\project\my project> npx cap migrate
[info] Please note this tool is not intended for use in a mono-repo enviroment, please check out the Ionic vscode
       extension for this functionality.
[?] Capacitor 4 sets a deployment target of iOS 13 and Android 12 (SDK 32).

√ Are you sure you want to migrate? (Y/n) ... y
[?] Would you like the migrator to run npm install to install the latest versions of capacitor packages? (Those using
    other package managers should answer N)
√ Run Npm Install? (Y/n) ... y
√ Installing Latest NPM Modules. in 24.88s
√ Migrating @capacitor/storage to @capacitor/preferences. in 22.07ms
√ Migrating AndroidManifest.xml by adding android:exported attribute to Activity. in 34.98ms
[?] Some projects still require JCenter to function. If your project does, please answer yes below.
√ Keep JCenter if present? (y/N) ... n
[info] Set com.android.tools.build:gradle = 7.2.1.
[info] Set com.google.gms:google-services = 4.3.13.
[info] Removed jcenter().
[info] Added mavenCentral().
[info] Removed jcenter().
[info] Added mavenCentral().
√ Migrating build.gradle file. in 154.13ms
√ Migrating app/build.gradle file. in 10.86ms
√ Migrating gradle-wrapper.properties by updating gradle version from 7.0 to 7.4.2. in 1.67ms
√ Migrating variables.gradle file. in 18.46ms
√ Migrating MainActivity in 7.29ms
√ Migrate to Android 12 Splashscreen and apply DayNight theme. in 16.35ms
√ Running cap sync. in 9.72s
√ Upgrading gradle wrapper files in 30.69s
[info] IMPORTANT: Review https://capacitorjs.com/docs/updating/4-0#plugins for breaking changes in these plugins that
       you use: @capacitor/local-notifications.
[info] Warning: The Android Gradle plugin was updated and it requires Java 11 to run. You may need to select this in
       Android Studio.
√ Writing breaking changes. in 2.84ms
[success] Migration to Capacitor ^4.0.0 is complete. Run and test your app!
PS D:\project\my project>

Android 업데이트

업데이트 이후 android studio에서 build를 하면 아래와 같은 메시지를 만난다.
여기서 Sync project 만 클릭해도 에러는 자동으로 해결된다.

Gradle sync needed
Project was built with Android Gradle Plugin (AGP) 7.2.1 but it is synced with 7.2.0.
Please sync the project with Gradle Files.
Sync project

평점을 남겨주세요
평점 : 5.0
총 투표수 : 1

질문 및 답글