Skip to content

Commit f6eb7bc

Browse files
chore(flutter): update android section of Amplify Flutter getting started guide (#7760)
* chore: update android section of Flutter getting started guide * chore: update gen 2 flutter platform setup * chore: add info to enable network permissions on android * chore: update H3 headers to H2 * chore: update min Xcode version to 15 * chore: update xcode verison to 15.0 for macOS * chore: update ios and macos setup to be consistent with Android, add callout for missing podfile
1 parent c0de6d8 commit f6eb7bc

File tree

6 files changed

+274
-55
lines changed

6 files changed

+274
-55
lines changed

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@
532532
"Didfinishlaunchingwithoptions",
533533
"displayMode",
534534
"displayOrder",
535+
"dists",
535536
"DocSet",
536537
"DocSets",
537538
"Donef",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ compileOptions {
2020
// add this line to support Java8 features
2121
coreLibraryDesugaringEnabled true
2222
23-
sourceCompatibility JavaVersion.VERSION_1_8
24-
targetCompatibility JavaVersion.VERSION_1_8
23+
sourceCompatibility JavaVersion.VERSION_17
24+
targetCompatibility JavaVersion.VERSION_17
2525
}
2626
```
2727

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,81 @@
1-
Amplify requires a minimum of API level 24 (Android 7.0), Gradle 7 and Kotlin > 1.9 when targeting Android.
1+
Amplify Flutter supports API level 24+ (Android 7.0+), and requires Gradle 8+, Kotlin 1.9+, and Java 17+ when targeting Android. Follow the steps below to apply these changes in your app.
22

3-
_If your Flutter app was generated with Flutter 3.16 or lower, please follow the migration guide [here](https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply)._
3+
<Callout warning>
4+
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.
5+
</Callout>
46

5-
From your project root, navigate to the `android/` directory and open `settings.gradle` in the text editor of your choice. Update the Gradle plugin version to 7.4.2 or higher:
7+
1. Open `android/settings.gradle` and update the Android Gradle plugin and kotlin versions:
68

7-
```diff
8-
plugins {
9-
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
10-
- id "com.android.application" version "7.3.0" apply false
11-
+ id "com.android.application" version "7.4.2" apply false
12-
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
13-
}
9+
```diff title="android/settings.gradle"
10+
plugins {
11+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
12+
- id "com.android.application" version "7.3.0" apply false
13+
- id "org.jetbrains.kotlin.android" version "1.7.10" apply false
14+
+ id "com.android.application" version "8.1.0" apply false
15+
+ id "org.jetbrains.kotlin.android" version "1.9.10" apply false
16+
}
1417
```
1518

16-
Go to the `android/` directory and open `settings.gradle`. Update the Kotlin plugin version to 1.9.10 or higher:
17-
18-
```diff
19-
plugins {
20-
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version "7.3.0" apply false
22-
- id "org.jetbrains.kotlin.android" version "1.7.10" apply false
23-
+ id "org.jetbrains.kotlin.android" version "1.9.10" apply false
24-
}
25-
```
19+
2. Open `android/gradle/wrapper/gradle-wrapper.properties` and update the Gradle `distributionUrl`.
2620

27-
Then, open `android/gradle/wrapper/gradle-wrapper.properties`. Update the Gradle `distributionUrl` to a version between 7.3 and 7.6.1 (see the [Flutter docs](https://docs.flutter.dev/release/breaking-changes/android-java-gradle-migration-guide) for more info).
28-
29-
```diff
21+
```diff title="android/gradle/wrapper/gradle-wrapper.properties"
22+
distributionBase=GRADLE_USER_HOME
23+
distributionPath=wrapper/dists
24+
zipStoreBase=GRADLE_USER_HOME
25+
zipStorePath=wrapper/dists
3026
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
31-
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
27+
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
3228
```
3329

34-
Then, open `android/app/build.gradle`. Update the minimum Android SDK version to 24 or higher:
30+
3. Open `android/app/build.gradle` and update the Java version and minimum Android SDK version.
31+
32+
```diff title="android/app/build.gradle"
33+
android {
34+
namespace = "com.example.myapp"
35+
compileSdk = flutter.compileSdkVersion
36+
ndkVersion = flutter.ndkVersion
37+
compileOptions {
38+
- sourceCompatibility = JavaVersion.VERSION_1_8
39+
- targetCompatibility = JavaVersion.VERSION_1_8
40+
+ sourceCompatibility = JavaVersion.VERSION_17
41+
+ targetCompatibility = JavaVersion.VERSION_17
42+
}
3543

36-
```diff
3744
defaultConfig {
3845
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
39-
applicationId "com.example.myapp"
46+
applicationId = "com.example.myapp"
4047
// You can update the following values to match your application needs.
4148
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
42-
- minSdkVersion flutter.minSdkVersion
43-
+ minSdkVersion 24
44-
targetSdkVersion flutter.targetSdkVersion
45-
versionCode flutterVersionCode.toInteger()
46-
versionName flutterVersionName
49+
- minSdk = flutter.minSdkVersion
50+
+ minSdk = 24
51+
targetSdk = flutter.targetSdkVersion
52+
versionCode = flutterVersionCode.toInteger()
53+
versionName = flutterVersionName
4754
}
55+
56+
buildTypes {
57+
release {
58+
// TODO: Add your own signing config for the release build.
59+
// Signing with the debug keys for now, so `flutter run --release` works.
60+
signingConfig = signingConfigs.debug
61+
}
62+
}
63+
}
64+
```
65+
66+
<Callout info>
67+
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).
68+
</Callout>
69+
70+
### Network Permissions for Release Builds
71+
72+
Flutter apps have access to make network requests by default in debug mode. This permission needs to be added when building in release mode. To do this, open `android/app/src/main/AndroidManifest.xml` and make the following addition.
73+
74+
```xml title="android/app/src/main/AndroidManifest.xml"
75+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
76+
// highlight-start
77+
<uses-permission android:name="android.permission.INTERNET"/>
78+
// highlight-end
79+
...
80+
</manifest>
4881
```

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Amplify requires a minimum deployment target of 13.0 and Xcode 13.2 or higher when targeting iOS.
1+
Amplify requires a minimum deployment target of 13.0 and Xcode 15.0 or higher when targeting iOS.
22

33
From your project root, navigate to the `ios/` directory and open the `Podfile` in a text editor of your choice. At the top of the file, update the target iOS platform to 13.0 or higher.
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Amplify requires a minimum deployment target of 10.15 and Xcode 13.2 or higher when targeting macOS. Additionally, you will need to enable networking, keychain entitlements, and code signing.
1+
Amplify requires a minimum deployment target of 10.15 and Xcode 15.0 or higher when targeting macOS. Additionally, you will need to enable networking, keychain entitlements, and code signing.
22

33
### Update Minimum Version
44

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

Lines changed: 204 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,223 @@ export function getStaticProps(context) {
2222
}
2323

2424

25-
### iOS
26-
From your project root, navigate to the `ios/` directory and modify the `Podfile` using a text editor of your choice and update the target iOS platform to 11.0 or higher.
25+
## iOS
2726

28-
```bash
29-
platform :ios, '11.0'
27+
Amplify requires a minimum deployment target of 13.0 and Xcode 15.0 or higher when targeting iOS. Follow the steps below to update the minimum deployment target.
28+
29+
Open `ios/Podfile` and update the target iOS platform to 13.0 or higher.
30+
31+
<Callout info>
32+
If there is no file located at `ios/Podfile`, add `amplify_flutter` to your `pubspec.yaml` and run `pub get`. This will automatically create the file.
33+
</Callout>
34+
35+
```diff title="ios/Podfile"
36+
- # Uncomment this line to define a global platform for your project
37+
- # platform :ios, '12.0'
38+
+ platform :ios, '13.0'
3039
```
3140

32-
<Callout>
41+
Open your project in Xcode and select Runner, Targets -> Runner and then the "General" tab. Under the "Minimum Deployments" section, update the iOS version to 13.0 or higher.
42+
43+
![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)
3344

34-
When preparing your application for deployment, you should also update your iOS Deployment Target to at least 11.0. See the [Flutter docs](https://docs.flutter.dev/deployment/ios) to learn more about building your iOS app for release.
45+
Select Runner, Project -> Runner and then the "Info" tab. Update "iOS Deployment Target" to 13.0 or higher.
3546

47+
![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)
48+
49+
## Android
50+
51+
Amplify Flutter supports API level 24+ (Android 7.0+), and requires Gradle 8+, Kotlin 1.9+, and Java 17+ when targeting Android. Follow the steps below to apply these changes in your app.
52+
53+
<Callout warning>
54+
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.
3655
</Callout>
3756

38-
### Android
39-
From your project root, navigate to the `android/app/` directory and modify `build.gradle` using a text editor of your choice and update the target Android SDK version to 21 or higher:
57+
1. Open `android/settings.gradle` and update the Android Gradle plugin and kotlin versions:
4058

41-
```bash
42-
minSdkVersion 21
59+
```diff title="android/settings.gradle"
60+
plugins {
61+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
62+
- id "com.android.application" version "7.3.0" apply false
63+
- id "org.jetbrains.kotlin.android" version "1.7.10" apply false
64+
+ id "com.android.application" version "8.1.0" apply false
65+
+ id "org.jetbrains.kotlin.android" version "1.9.10" apply false
66+
}
4367
```
4468

45-
<Callout warning>
69+
2. Open `android/gradle/wrapper/gradle-wrapper.properties` and update the Gradle `distributionUrl`.
4670

47-
If you are using Flutter 2.10 or above, you will need to ensure that your app supports an [up-to-date Kotlin version](https://docs.flutter.dev/release/breaking-changes/kotlin-version).
48-
This will typically be version 1.5.31 or higher.
49-
<br />
50-
You can do this by updating the Kotlin version in your app's `android/build.gradle` file:
71+
```diff title="android/gradle/wrapper/gradle-wrapper.properties"
72+
distributionBase=GRADLE_USER_HOME
73+
distributionPath=wrapper/dists
74+
zipStoreBase=GRADLE_USER_HOME
75+
zipStorePath=wrapper/dists
76+
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
77+
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
78+
```
5179

52-
```yaml
53-
buildscript {
54-
ext.kotlin_version = '1.5.31'
55-
...
80+
3. Open `android/app/build.gradle` and update the Java version and minimum Android SDK version.
81+
82+
```diff title="android/app/build.gradle"
83+
android {
84+
namespace = "com.example.myapp"
85+
compileSdk = flutter.compileSdkVersion
86+
ndkVersion = flutter.ndkVersion
87+
compileOptions {
88+
- sourceCompatibility = JavaVersion.VERSION_1_8
89+
- targetCompatibility = JavaVersion.VERSION_1_8
90+
+ sourceCompatibility = JavaVersion.VERSION_17
91+
+ targetCompatibility = JavaVersion.VERSION_17
92+
}
93+
94+
defaultConfig {
95+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
96+
applicationId = "com.example.myapp"
97+
// You can update the following values to match your application needs.
98+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
99+
- minSdk = flutter.minSdkVersion
100+
+ minSdk = 24
101+
targetSdk = flutter.targetSdkVersion
102+
versionCode = flutterVersionCode.toInteger()
103+
versionName = flutterVersionName
104+
}
105+
106+
buildTypes {
107+
release {
108+
// TODO: Add your own signing config for the release build.
109+
// Signing with the debug keys for now, so `flutter run --release` works.
110+
signingConfig = signingConfigs.debug
111+
}
112+
}
56113
}
57114
```
58115

116+
<Callout info>
117+
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).
118+
</Callout>
119+
120+
### Network Permissions for Release Builds
121+
122+
Flutter apps have access to make network requests by default in debug mode. This permission needs to be added when building in release mode. To do this, open `android/app/src/main/AndroidManifest.xml` and make the following addition.
123+
124+
```xml title="android/app/src/main/AndroidManifest.xml"
125+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
126+
// highlight-start
127+
<uses-permission android:name="android.permission.INTERNET"/>
128+
// highlight-end
129+
...
130+
</manifest>
131+
```
132+
133+
## Web
134+
135+
There are no Amplify specific requirements or setup instructions when targeting web. You will need to use a browser supported by Flutter. See the following Flutter docs for more info:
136+
137+
- [Supported deployment platforms](https://docs.flutter.dev/reference/supported-platforms)
138+
- [FAQ: Which web browsers are supported by Flutter?](https://docs.flutter.dev/development/platform-integration/web/faq#which-web-browsers-are-supported-by-flutter)
139+
140+
## macOS
141+
142+
Amplify requires a minimum deployment target of 10.15 and Xcode 15.0 or higher when targeting macOS. Additionally, you will need to enable networking, keychain entitlements, and code signing.
143+
144+
### Update Minimum Version
145+
146+
Open `macos/Podfile` and update the target macOS platform to 10.15 or higher.
147+
148+
<Callout info>
149+
If there is no file located at `macos/Podfile`, add `amplify_flutter` to your `pubspec.yaml` and run `pub get`. This will automatically create the file.
59150
</Callout>
151+
152+
```diff title="ios/Podfile"
153+
- platform :osx, '10.14'
154+
+ platform :osx, '10.15'
155+
```
156+
157+
Open your project in Xcode and select Runner, Targets -> Runner and then the "General" tab. Under the "Minimum Deployments" section, update the macOS version to 10.15 or higher.
158+
159+
![Setting the macOS version to 10.15 or higher in the Minimum Deployments tab of the Runner general section.](/images/project-setup/flutter/mac/target-min-deployment-version.png)
160+
161+
Select Runner, Project -> Runner and then the "Info" tab. Update "macOS Deployment Target" to 10.15 or higher.
162+
163+
![Setting the macOS version to 10.15 or higher in the macOS Deployment Target tab of the Runner info section.](/images/project-setup/flutter/mac/project-min-deployment-version.png)
164+
165+
### Enable Network Calls
166+
167+
Open your project in Xcode and select Runner, Targets -> Runner and then the "Signing and Capabilities" tab. Under "App Sandbox" select "Outgoing Connections (Client)".
168+
169+
![Selecting outgoing connections in the app sandbox section of the runner signing and capabilities tab.](/images/project-setup/flutter/mac/xcode-entitlements.png)
170+
171+
For more info on the Networking entitlement, see Apple's documentation on [com.apple.security.network.client](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_network_client).
172+
173+
### Enable Keychain Sharing
174+
175+
<Callout info>
176+
177+
This capability is required because Amplify uses the Data Protection Keychain on macOS as a platform best practice.
178+
See [TN3137: macOS keychain APIs and implementations](https://developer.apple.com/documentation/technotes/tn3137-on-mac-keychains)
179+
for more information on how Keychain works on macOS and the Keychain Sharing entitlement.
180+
181+
</Callout>
182+
183+
Open your project in Xcode and select Runner, Targets -> Runner and then the "Signing and Capabilities" tab.
184+
185+
1. Click the "+ icon".
186+
187+
![Plus icon circled in the signing and capabilities section of the runner tab.](/images/project-setup/flutter/mac/enable-keychain-access.png)
188+
189+
2. Search for "Keychain Sharing" in the subsequent modal, and add it.
190+
191+
![Keychain Sharing search result after searching keychain.](/images/project-setup/flutter/mac/search-keychain-sharing.png)
192+
193+
3. Scroll down to "Keychain Sharing" in the "Signing and Capabilities" and click the "+" icon. By default, your bundle ID will be used.
194+
195+
![Plus icon highlighted in the keychain sharing section of the signing and capabilities section of runner.](/images/project-setup/flutter/mac/adding-keychain-access-group.png)
196+
197+
4. Finally, add a development team and enable signing.
198+
199+
![Team selector and Enable Development Signing button highlighted in the signing and capabilities section of the runner tab.](/images/project-setup/flutter/mac/enable-signing.png)
200+
201+
202+
## Windows
203+
204+
There are no Amplify specific requirements or setup instructions when targeting Windows. You will need to use a Windows version supported by Flutter. See the following Flutter docs for more info:
205+
206+
- [Supported deployment platforms](https://docs.flutter.dev/reference/supported-platforms)
207+
208+
## Linux
209+
210+
Amplify Flutter depends on the [libsecret](https://wiki.gnome.org/Projects/Libsecret) library when targeting Linux.
211+
212+
### Local Development
213+
214+
To run and debug an app that depends on Amplify Flutter, you must install `libsecret-1-dev`. Run the following commands to install `libsecret-1-dev`. this will also install dependencies of `libsecret-1-dev`, such as `libglib2.0-dev`.
215+
216+
<Callout info>
217+
The command below is intended for Ubuntu. The command may vary on other Linux distributions.
218+
</Callout>
219+
220+
{/* cSpell:disable */}
221+
222+
```terminal
223+
sudo apt-get update
224+
sudo apt-get install -y libsecret-1-dev
225+
```
226+
227+
{/* cSpell:enable */}
228+
229+
### Packaging Your App
230+
231+
To include the required dependencies when packaging your app with Snapcraft, include them in your `snapcraft.yaml` file. For more info, see [Flutter's documentation on releasing to the Snap Store](https://docs.flutter.dev/deployment/linux).
232+
233+
```yaml
234+
parts:
235+
my-app:
236+
plugin: flutter
237+
source: .
238+
flutter-target: lib/main.dart
239+
build-packages:
240+
- libsecret-1-dev
241+
stage-packages:
242+
- libsecret-1-0
243+
```
244+

0 commit comments

Comments
 (0)