Skip to main content
Version: v4

Updating a Capacitor v3 plugin to 4.0

There are only a few changes required to update a plugin from Capacitor 3 to Capacitor 4.

info

While you can follow the manual steps below, check out this tool from community member @rdlabo that automatically updates a Capacitor 3 plugin to v4.

Android

Update Android Project Variables

In your build.gradle file, update your values to the following new minimums:

minSdkVersion = 22
compileSdkVersion = 32
targetSdkVersion = 32
androidxAppCompatVersion = '1.4.2'
junitVersion = '4.13.2'
androidxJunitVersion = '1.1.3'
androidxEspressoCoreVersion = '3.4.0'

Update to Gradle 7

Adjust your Gradle project settings in File > Project Structure > Project. The Android Gradle Plugin Version should be 7.2.1 or later and the Gradle Version should be 7.4.2 or later. Apply these changes and run a gradle sync by clicking on the Elephant Icon in the top right of Android Studio.

info

Android Studio may provide an automatic migration to Gradle 7. Go ahead and take them up on the offer! To upgrade, go to your build.gradle file, and click on the πŸ’‘ icon, and click "Upgrade Gradle. Once your project is migrated over, run a gradle sync as described above.

Another alternative would be to use the Android Gradle Plugin Upgrade Assistant to handle the migration for you. Steps for this tool can be found in the Android documentation.

Ensure you are using Java 11

Capacitor 3 works with both Java 8 and Java 11. Moving forward, Capacitor 4 will only support Java 11. You can change this in your project by going to the following menu in Android Studio:

Preferences > Build, Execution, Deployment > Build Tools > Gradle

From there, you can modify the "Gradle JDK" to be Java 11.

info

Java 11 ships with the latest version of Android Studio. No additional downloads needed!

Remove jcenter() from the Gradle files

In previous Capacitor versions, jcenter() was required due to our Cordova compatibility layer being hosted on Jcenter. However, we are now using the latest Cordova Android version, hosted on Maven Central. With this, you may be able to remove jcenter() entirely from your build.gradle file. If you are using other native dependencies, make sure they aren't hosted on Jcenter before removing it!

iOS

Raise iOS Deployment Target

Do the following to your Xcode project: select the Project within the project editor and open the Build Settings tab. Under the Deployment section, change iOS Deployment Target to iOS 13.0. Repeat the same steps for any app Targets.

Then, openΒ ios/App/PodfileΒ and update the iOS version to 13.0:

platform :ios, '13.0'

Next, update the podspec file at the root of the project:

s.ios.deployment_target  = '13.0'