Skip to content

Flutter: update platform setup #8271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ dependencies:

### Update The Android Project

<BlockSwitcher>
<Block name="Gradle Kotlin">
1. Open `android/app/build.gradle.kts` and enable `isCoreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.

```diff title="android/app/build.gradle.kts"
compileOptions {
+ isCoreLibraryDesugaringEnabled = true

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
```

2. Add the following dependency in `dependencies`.

```diff title="android/app/build.gradle.kts"
dependencies {
+ coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
+ implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10")
}
```
</Block>
<Block name="Gradle Groovy">
Open `build.gradle` located under `android/app`, and enable `coreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.

```groovy
Expand All @@ -35,3 +58,5 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
```
</Block>
</BlockSwitcher>
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,36 @@ import fcmPreReq from '/src/fragments/lib-v1/push-notifications/android/getting_

### Applying the Google services plugin

<BlockSwitcher>
<Block name="Gradle Kotlin">
1. Open `android/settings.gradle.kts` and add the Google Services plugin:
```diff title="android/settings.gradle.kts"
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.1.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
+ id("com.google.gms.google-services") version "4.3.14" apply false
}
```
2. Open `android/app/build.gradle.kts` and add the Google Services plugin:
```diff title="android/app/build.gradle.kts"
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
+ id("com.google.gms.google-services")
}
```
</Block>
<Block name="Gradle Groovy">
The Firebase documentation directs you to add the Google services plugin to your app `build.gradle` using the [Gradle plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block). However, we recommend you continue to use the [Legacy Plugin Application](https://docs.gradle.org/current/userguide/plugins.html#sec:old_plugin_application) instead:

```groovy
apply plugin: 'com.google.gms.google-services'
```
</Block>
</BlockSwitcher>

If you prefer using the plugins DSL, you should add the `plugins` block to the very top of the file or you may experience issues when building your app for Android.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ dependencies:

### Update The Android Project

<BlockSwitcher>
<Block name="Gradle Kotlin">
1. Open `android/app/build.gradle.kts` and enable `isCoreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.

```diff title="android/app/build.gradle.kts"
compileOptions {
+ isCoreLibraryDesugaringEnabled = true

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
```

2. Add the following dependency in `dependencies`.

```diff title="android/app/build.gradle.kts"
dependencies {
+ coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
+ implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10")
}
```
</Block>
<Block name="Gradle Groovy">
Open `build.gradle` located under `android/app`, and enable `coreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.

```groovy
Expand All @@ -35,3 +58,5 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
```
</Block>
</BlockSwitcher>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,73 @@ Amplify Flutter supports API level 24+ (Android 7.0+), and requires Gradle 8+, K
The steps below are intended for Flutter apps created with Flutter version 3.16+. If your app was created prior to version 3.16, please follow the guide [here](https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply) to migrate to Gradle's declarative plugins block before following the steps below.
</Callout>

<BlockSwitcher>
<Block name="Gradle Kotlin">
1. Open `android/settings.gradle.kts` and update the Android Gradle plugin and kotlin versions:

```diff title="android/settings.gradle.kts"
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
- id("com.android.application") version "8.7.0" apply false
- id("org.jetbrains.kotlin.android") version "1.8.22" apply false
+ id("com.android.application") version "8.1.0" apply false
+ id("org.jetbrains.kotlin.android") version "1.9.10" apply false
}
```

2. Open `android/gradle/wrapper/gradle-wrapper.properties` and update the Gradle `distributionUrl`.

```diff title="android/gradle/wrapper/gradle-wrapper.properties"
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
```

3. Open `android/app/build.gradle.kts` and update the Java version and minimum Android SDK version.

```diff title="android/app/build.gradle.kts"
android {
namespace = "com.example.myapp"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
- sourceCompatibility = JavaVersion.VERSION_11
- targetCompatibility = JavaVersion.VERSION_11
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
- jvmTarget = JavaVersion.VERSION_11.toString()
+ jvmTarget = JavaVersion.VERSION_17.toString()
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.myapp"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
- minSdk = flutter.minSdkVersion
+ minSdk = 24
targetSdk = flutter.targetSdkVersion
versionCode = flutterVersionCode.toInteger()
versionName = flutterVersionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
}
}
}
```
</Block>
<Block name="Gradle Groovy">
1. Open `android/settings.gradle` and update the Android Gradle plugin and kotlin versions:

```diff title="android/settings.gradle"
Expand Down Expand Up @@ -62,6 +129,8 @@ android {
}
}
```
</Block>
</BlockSwitcher>

<Callout info>
If you would like to use a higher version of Gradle or Android Gradle plugin see the compatibility matrix [here](https://developer.android.com/build/releases/gradle-plugin#updating-gradle).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Open your project in Xcode and select Runner, Targets -> Runner and then the "Ge

![Setting the iOS version to 13.0 or higher in the minimum deployments section of the Runner general window.](/images/project-setup/flutter/ios/target-min-deployment-version.png)

Select Runner, Project -> Runner and then the "Info" tab. Update "iOS Deployment Target" to 13.0 or higher.
Select Runner, Project -> Runner and then the "Build Settings" tab. Update "iOS Deployment Target" to 13.0 or higher.

![Setting the iOS version to 13.0 or higher in the deployment targets section of the Runner info window.](/images/project-setup/flutter/ios/project-min-deployment-version.png)
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,36 @@ If you prefer using the plugins DSL, you should add the `plugins` block to the v
</InlineFilter>

<InlineFilter filters={['flutter']}>

<BlockSwitcher>
<Block name="Gradle Kotlin">
1. Open `android/settings.gradle.kts` and add the Google Services plugin:
```diff title="android/settings.gradle.kts"
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.1.0" apply false
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
+ id("com.google.gms.google-services") version "4.3.14" apply false
}
```
2. Open `android/app/build.gradle.kts` and add the Google Services plugin:
```diff title="android/app/build.gradle.kts"
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
+ id("com.google.gms.google-services")
}
```
</Block>
<Block name="Gradle Groovy">
The Firebase documentation directs you to add the Google services plugin to your app `settings.gradle` using the [Gradle plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block). However, we recommend you continue to use the [Legacy Plugin Application](https://docs.gradle.org/current/userguide/plugins.html#sec:old_plugin_application) instead:

```groovy
```groovy title="android/settings.gradle"
id "com.google.gms:google-services" version "4.3.14" apply false
```
</Block>
</BlockSwitcher>

</InlineFilter>

Expand Down
71 changes: 70 additions & 1 deletion src/pages/[platform]/start/platform-setup/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Open your project in Xcode and select Runner, Targets -> Runner and then the "Ge

![Setting the iOS version to 13.0 or higher in the minimum deployments section of the Runner general window.](/images/project-setup/flutter/ios/target-min-deployment-version.png)

Select Runner, Project -> Runner and then the "Info" tab. Update "iOS Deployment Target" to 13.0 or higher.
Select Runner, Project -> Runner and then the "Build Settings" tab. Update "iOS Deployment Target" to 13.0 or higher.

![Setting the iOS version to 13.0 or higher in the deployment targets section of the Runner info window.](/images/project-setup/flutter/ios/project-min-deployment-version.png)

Expand All @@ -54,6 +54,73 @@ Amplify Flutter supports API level 24+ (Android 7.0+), and requires Gradle 8+, K
The steps below are intended for Flutter apps created with Flutter version 3.16+. If your app was created prior to version 3.16, please follow the guide [here](https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply) to migrate to Gradle's declarative plugins block before following the steps below.
</Callout>

<BlockSwitcher>
<Block name="Gradle Kotlin">
1. Open `android/settings.gradle.kts` and update the Android Gradle plugin and kotlin versions:

```diff title="android/settings.gradle.kts"
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
- id("com.android.application") version "8.7.0" apply false
- id("org.jetbrains.kotlin.android") version "1.8.22" apply false
+ id("com.android.application") version "8.1.0" apply false
+ id("org.jetbrains.kotlin.android") version "1.9.10" apply false
}
```

2. Open `android/gradle/wrapper/gradle-wrapper.properties` and update the Gradle `distributionUrl`.

```diff title="android/gradle/wrapper/gradle-wrapper.properties"
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
```

3. Open `android/app/build.gradle.kts` and update the Java version and minimum Android SDK version.

```diff title="android/app/build.gradle.kts"
android {
namespace = "com.example.myapp"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
- sourceCompatibility = JavaVersion.VERSION_11
- targetCompatibility = JavaVersion.VERSION_11
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
- jvmTarget = JavaVersion.VERSION_11.toString()
+ jvmTarget = JavaVersion.VERSION_17.toString()
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.myapp"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
- minSdk = flutter.minSdkVersion
+ minSdk = 24
targetSdk = flutter.targetSdkVersion
versionCode = flutterVersionCode.toInteger()
versionName = flutterVersionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
}
}
}
```
</Block>
<Block name="Gradle Groovy">
1. Open `android/settings.gradle` and update the Android Gradle plugin and kotlin versions:

```diff title="android/settings.gradle"
Expand Down Expand Up @@ -112,6 +179,8 @@ android {
}
}
```
</Block>
</BlockSwitcher>

<Callout info>
If you would like to use a higher version of Gradle or Android Gradle plugin see the compatibility matrix [here](https://developer.android.com/build/releases/gradle-plugin#updating-gradle).
Expand Down