Skip to content

Commit f503812

Browse files
authored
Flutter: Update platform setup for Gradle Kotlin (#8271)
- Updated Flutter Platform Setup instructions for locating iOS Deployment Target in Xcode - Updated Flutter Platform Setup instructions to include Gradle Kotlin - Updated Flutter Push Notification Setup instructions to include Gradle Kotlin - Updated Flutter DataStore Setup instructions to include Gradle Kotlin
1 parent 4a39f72 commit f503812

File tree

8 files changed

+241
-4
lines changed

8 files changed

+241
-4
lines changed
174 KB
Loading

src/fragments/lib-v1/datastore/flutter/getting-started/20_installLib.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@ dependencies:
1313
1414
### Update The Android Project
1515
16+
<BlockSwitcher>
17+
<Block name="Gradle Kotlin">
18+
1. Open `android/app/build.gradle.kts` and enable `isCoreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.
19+
20+
```diff title="android/app/build.gradle.kts"
21+
compileOptions {
22+
+ isCoreLibraryDesugaringEnabled = true
23+
24+
sourceCompatibility = JavaVersion.VERSION_17
25+
targetCompatibility = JavaVersion.VERSION_17
26+
}
27+
```
28+
29+
2. Add the following dependency in `dependencies`.
30+
31+
```diff title="android/app/build.gradle.kts"
32+
dependencies {
33+
+ coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
34+
+ implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10")
35+
}
36+
```
37+
</Block>
38+
<Block name="Gradle Groovy">
1639
Open `build.gradle` located under `android/app`, and enable `coreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.
1740

1841
```groovy
@@ -35,3 +58,5 @@ dependencies {
3558
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3659
}
3760
```
61+
</Block>
62+
</BlockSwitcher>

src/fragments/lib-v1/push-notifications/common/getting_started/cross-platform-prereq.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,36 @@ import fcmPreReq from '/src/fragments/lib-v1/push-notifications/android/getting_
3333

3434
### Applying the Google services plugin
3535

36+
<BlockSwitcher>
37+
<Block name="Gradle Kotlin">
38+
1. Open `android/settings.gradle.kts` and add the Google Services plugin:
39+
```diff title="android/settings.gradle.kts"
40+
plugins {
41+
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
42+
id("com.android.application") version "8.1.0" apply false
43+
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
44+
+ id("com.google.gms.google-services") version "4.3.14" apply false
45+
}
46+
```
47+
2. Open `android/app/build.gradle.kts` and add the Google Services plugin:
48+
```diff title="android/app/build.gradle.kts"
49+
plugins {
50+
id("com.android.application")
51+
id("kotlin-android")
52+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
53+
id("dev.flutter.flutter-gradle-plugin")
54+
+ id("com.google.gms.google-services")
55+
}
56+
```
57+
</Block>
58+
<Block name="Gradle Groovy">
3659
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:
3760

3861
```groovy
3962
apply plugin: 'com.google.gms.google-services'
4063
```
64+
</Block>
65+
</BlockSwitcher>
4166

4267
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.
4368

src/fragments/lib/datastore/flutter/getting-started/20_installLib.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@ dependencies:
1313
1414
### Update The Android Project
1515
16+
<BlockSwitcher>
17+
<Block name="Gradle Kotlin">
18+
1. Open `android/app/build.gradle.kts` and enable `isCoreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.
19+
20+
```diff title="android/app/build.gradle.kts"
21+
compileOptions {
22+
+ isCoreLibraryDesugaringEnabled = true
23+
24+
sourceCompatibility = JavaVersion.VERSION_17
25+
targetCompatibility = JavaVersion.VERSION_17
26+
}
27+
```
28+
29+
2. Add the following dependency in `dependencies`.
30+
31+
```diff title="android/app/build.gradle.kts"
32+
dependencies {
33+
+ coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
34+
+ implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10")
35+
}
36+
```
37+
</Block>
38+
<Block name="Gradle Groovy">
1639
Open `build.gradle` located under `android/app`, and enable `coreLibraryDesugaringEnabled` in `compileOptions` to support the Java8 feature used in the DataStore plugin.
1740

1841
```groovy
@@ -35,3 +58,5 @@ dependencies {
3558
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3659
}
3760
```
61+
</Block>
62+
</BlockSwitcher>

src/fragments/lib/project-setup/flutter/platform-setup/android.mdx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,73 @@ Amplify Flutter supports API level 24+ (Android 7.0+), and requires Gradle 8+, K
44
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.
55
</Callout>
66

7+
<BlockSwitcher>
8+
<Block name="Gradle Kotlin">
9+
1. Open `android/settings.gradle.kts` and update the Android Gradle plugin and kotlin versions:
10+
11+
```diff title="android/settings.gradle.kts"
12+
plugins {
13+
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
14+
- id("com.android.application") version "8.7.0" apply false
15+
- id("org.jetbrains.kotlin.android") version "1.8.22" apply false
16+
+ id("com.android.application") version "8.1.0" apply false
17+
+ id("org.jetbrains.kotlin.android") version "1.9.10" apply false
18+
}
19+
```
20+
21+
2. Open `android/gradle/wrapper/gradle-wrapper.properties` and update the Gradle `distributionUrl`.
22+
23+
```diff title="android/gradle/wrapper/gradle-wrapper.properties"
24+
distributionBase=GRADLE_USER_HOME
25+
distributionPath=wrapper/dists
26+
zipStoreBase=GRADLE_USER_HOME
27+
zipStorePath=wrapper/dists
28+
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
29+
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
30+
```
31+
32+
3. Open `android/app/build.gradle.kts` and update the Java version and minimum Android SDK version.
33+
34+
```diff title="android/app/build.gradle.kts"
35+
android {
36+
namespace = "com.example.myapp"
37+
compileSdk = flutter.compileSdkVersion
38+
ndkVersion = flutter.ndkVersion
39+
compileOptions {
40+
- sourceCompatibility = JavaVersion.VERSION_11
41+
- targetCompatibility = JavaVersion.VERSION_11
42+
+ sourceCompatibility = JavaVersion.VERSION_17
43+
+ targetCompatibility = JavaVersion.VERSION_17
44+
}
45+
46+
kotlinOptions {
47+
- jvmTarget = JavaVersion.VERSION_11.toString()
48+
+ jvmTarget = JavaVersion.VERSION_17.toString()
49+
}
50+
51+
defaultConfig {
52+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
53+
applicationId = "com.example.myapp"
54+
// You can update the following values to match your application needs.
55+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
56+
- minSdk = flutter.minSdkVersion
57+
+ minSdk = 24
58+
targetSdk = flutter.targetSdkVersion
59+
versionCode = flutterVersionCode.toInteger()
60+
versionName = flutterVersionName
61+
}
62+
63+
buildTypes {
64+
release {
65+
// TODO: Add your own signing config for the release build.
66+
// Signing with the debug keys for now, so `flutter run --release` works.
67+
signingConfig = signingConfigs.debug
68+
}
69+
}
70+
}
71+
```
72+
</Block>
73+
<Block name="Gradle Groovy">
774
1. Open `android/settings.gradle` and update the Android Gradle plugin and kotlin versions:
875

976
```diff title="android/settings.gradle"
@@ -62,6 +129,8 @@ android {
62129
}
63130
}
64131
```
132+
</Block>
133+
</BlockSwitcher>
65134

66135
<Callout info>
67136
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).

src/fragments/lib/project-setup/flutter/platform-setup/ios.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Open your project in Xcode and select Runner, Targets -> Runner and then the "Ge
1010

1111
![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)
1212

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

1515
![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)

src/fragments/lib/push-notifications/common/getting_started/cross-platform-prereq.mdx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,36 @@ If you prefer using the plugins DSL, you should add the `plugins` block to the v
4545
</InlineFilter>
4646

4747
<InlineFilter filters={['flutter']}>
48-
48+
<BlockSwitcher>
49+
<Block name="Gradle Kotlin">
50+
1. Open `android/settings.gradle.kts` and add the Google Services plugin:
51+
```diff title="android/settings.gradle.kts"
52+
plugins {
53+
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
54+
id("com.android.application") version "8.1.0" apply false
55+
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
56+
+ id("com.google.gms.google-services") version "4.3.14" apply false
57+
}
58+
```
59+
2. Open `android/app/build.gradle.kts` and add the Google Services plugin:
60+
```diff title="android/app/build.gradle.kts"
61+
plugins {
62+
id("com.android.application")
63+
id("kotlin-android")
64+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
65+
id("dev.flutter.flutter-gradle-plugin")
66+
+ id("com.google.gms.google-services")
67+
}
68+
```
69+
</Block>
70+
<Block name="Gradle Groovy">
4971
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:
5072

51-
```groovy
73+
```groovy title="android/settings.gradle"
5274
id "com.google.gms:google-services" version "4.3.14" apply false
5375
```
76+
</Block>
77+
</BlockSwitcher>
5478

5579
</InlineFilter>
5680

src/pages/[platform]/start/platform-setup/index.mdx

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Open your project in Xcode and select Runner, Targets -> Runner and then the "Ge
4242

4343
![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)
4444

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

4747
![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)
4848

@@ -54,6 +54,73 @@ Amplify Flutter supports API level 24+ (Android 7.0+), and requires Gradle 8+, K
5454
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.
5555
</Callout>
5656

57+
<BlockSwitcher>
58+
<Block name="Gradle Kotlin">
59+
1. Open `android/settings.gradle.kts` and update the Android Gradle plugin and kotlin versions:
60+
61+
```diff title="android/settings.gradle.kts"
62+
plugins {
63+
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
64+
- id("com.android.application") version "8.7.0" apply false
65+
- id("org.jetbrains.kotlin.android") version "1.8.22" apply false
66+
+ id("com.android.application") version "8.1.0" apply false
67+
+ id("org.jetbrains.kotlin.android") version "1.9.10" apply false
68+
}
69+
```
70+
71+
2. Open `android/gradle/wrapper/gradle-wrapper.properties` and update the Gradle `distributionUrl`.
72+
73+
```diff title="android/gradle/wrapper/gradle-wrapper.properties"
74+
distributionBase=GRADLE_USER_HOME
75+
distributionPath=wrapper/dists
76+
zipStoreBase=GRADLE_USER_HOME
77+
zipStorePath=wrapper/dists
78+
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
79+
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
80+
```
81+
82+
3. Open `android/app/build.gradle.kts` and update the Java version and minimum Android SDK version.
83+
84+
```diff title="android/app/build.gradle.kts"
85+
android {
86+
namespace = "com.example.myapp"
87+
compileSdk = flutter.compileSdkVersion
88+
ndkVersion = flutter.ndkVersion
89+
compileOptions {
90+
- sourceCompatibility = JavaVersion.VERSION_11
91+
- targetCompatibility = JavaVersion.VERSION_11
92+
+ sourceCompatibility = JavaVersion.VERSION_17
93+
+ targetCompatibility = JavaVersion.VERSION_17
94+
}
95+
96+
kotlinOptions {
97+
- jvmTarget = JavaVersion.VERSION_11.toString()
98+
+ jvmTarget = JavaVersion.VERSION_17.toString()
99+
}
100+
101+
defaultConfig {
102+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
103+
applicationId = "com.example.myapp"
104+
// You can update the following values to match your application needs.
105+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
106+
- minSdk = flutter.minSdkVersion
107+
+ minSdk = 24
108+
targetSdk = flutter.targetSdkVersion
109+
versionCode = flutterVersionCode.toInteger()
110+
versionName = flutterVersionName
111+
}
112+
113+
buildTypes {
114+
release {
115+
// TODO: Add your own signing config for the release build.
116+
// Signing with the debug keys for now, so `flutter run --release` works.
117+
signingConfig = signingConfigs.debug
118+
}
119+
}
120+
}
121+
```
122+
</Block>
123+
<Block name="Gradle Groovy">
57124
1. Open `android/settings.gradle` and update the Android Gradle plugin and kotlin versions:
58125

59126
```diff title="android/settings.gradle"
@@ -112,6 +179,8 @@ android {
112179
}
113180
}
114181
```
182+
</Block>
183+
</BlockSwitcher>
115184

116185
<Callout info>
117186
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).

0 commit comments

Comments
 (0)