Skip to content

Commit

Permalink
docs: Add page for migrating plugins to Capacitor 7 (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Dec 20, 2024
1 parent eb10deb commit e8144b8
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 0 deletions.
144 changes: 144 additions & 0 deletions docs/main/updating/plugins/7-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
title: Updating plugins to 7.0
description: Guide for updating Capacitor from v6 to v7 in your plugin
slug: /updating/plugins/7-0
---

# Breaking changes in code

Plugin's `success()` and `error()` methods have been removed, use `resolve()` and `reject()` instead.

Some deprecated plugin definitions and methods such as `registerWebPlugin` have been removed, check the Capacitor 3 plugins upgrade guide for more information.

Capacitor's helper properties `platform` and `isNative` have been removed, use `getPlatform()` and `isNativePlatform()` methods instead.

## Android

`BridgeFragment` class has been removed, if a plugin was using that class to present a `Fragment`, they'll have to create their own version of it.

## iOS

### Add SPM support

Capacitor 6 added experimental SPM support, you can add support for your plugin following [Converting existing plugins to SPM](../../ios/spm.md#converting-existing-plugins-to-spm)

# Updating Capacitor to 7.0 in your plugin

## Using @capacitor/plugin-migration-v6-to-v7

From the plugin folder, run `npx @capacitor/plugin-migration-v6-to-v7@latest` and it will perform all the file changes automatically.

## Updating the files manually

### Updating package.json

Update `@capacitor/cli`, `@capacitor/core`, `@capacitor/android` and `@capacitor/ios` to `next` version.

### Update Android Plugin Variables

In your `build.gradle` file, update the following package version minimums:

```diff
ext {
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
}
```

### Update targetSDK / compileSDK to 35 and minSDK to 23

```diff
# build.gradle

android {
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
defaultConfig {
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
...
}
}
```

### Update gradle plugin to 8.7.2

```diff
dependencies {
- classpath 'com.android.tools.build:gradle:8.2.1'
+ classpath 'com.android.tools.build:gradle:8.7.2'
}
```

### Update gradle wrapper to 8.11.1

```diff
# gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
```

### Update to Java 21

```diff
# build.gradle
compileOptions {
- sourceCompatibility JavaVersion.VERSION_17
+ sourceCompatibility JavaVersion.VERSION_21
- targetCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_21
}
```

### Update kotlin_version

If your plugin uses kotlin, update the default `kotlin_version`

```diff
# build.gradle
buildscript {
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.25'
repositories {
```

### Raise iOS Deployment Target to 14

Update your plugin's .podspec file

```diff
- s.ios.deployment_target = '13.0'
+ s.ios.deployment_target = '14.0'
```

#### SPM compatible plugins

Update `Package.swift` file

```diff
- platforms: [.iOS(.v13)],
+ platforms: [.iOS(.v14)],
```

#### Plugins with old structure

Do the following for 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 14.0**. Repeat the same steps for any app **Targets**.

Then, open `ios/Podfile` and update the iOS version to 14.0:

```diff
-platform :ios, '13.0'
+platform :ios, '14.0'
```
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
collapsed: false,
items: [
'main/updating/7-0',
'main/updating/plugins/7-0',
'main/updating/6-0',
'main/updating/plugins/6-0',
'main/updating/5-0',
Expand Down

0 comments on commit e8144b8

Please sign in to comment.