Skip to content

Commit 0b77a2f

Browse files
sfshaza2gemini-code-assist[bot]jesswrd
authored
Add Kotlin DSL examples to Android build docs (#13034)
Adds Kotlin DSL (KTS) examples to , , , and using the component, alongside existing Groovy examples. The differences between Groovy and Kotlin are very minor. Staged: (TWO TABS) https://flutter-docs-prod--pr13034-kotlin-dsl-examples-1n9zftf7.web.app/add-to-app/android/plugin-setup (ONE TAB) https://flutter-docs-prod--pr13034-kotlin-dsl-examples-1n9zftf7.web.app/packages-and-plugins/using-packages (TWO TABS) https://flutter-docs-prod--pr13034-kotlin-dsl-examples-1n9zftf7.web.app/perf/deferred-components (THREE TABS) https://flutter-docs-prod--pr13034-kotlin-dsl-examples-1n9zftf7.web.app/platform-integration/android/compose-activity --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: jesswrd <jessiewong401@gmail.com>
1 parent 63663f7 commit 0b77a2f

4 files changed

Lines changed: 185 additions & 7 deletions

File tree

src/content/add-to-app/android/plugin-setup.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ does (transitively via a plugin).
7575

7676
For instance, your existing app's Gradle might already have:
7777

78-
```groovy title="ExistingApp/app/build.gradle"
78+
<Tabs key="existing-app-dependencies-1">
79+
<Tab name="Kotlin">
80+
81+
```kotlin title="ExistingApp/app/build.gradle.kts"
7982
8083
dependencies {
8184
@@ -85,6 +88,22 @@ dependencies {
8588
8689
```
8790

91+
</Tab>
92+
<Tab name="Groovy">
93+
94+
```groovy title="ExistingApp/app/build.gradle"
95+
96+
dependencies {
97+
98+
implementation "com.crashlytics.sdk.android:crashlytics:2.10.1"
99+
100+
}
101+
102+
```
103+
104+
</Tab>
105+
</Tabs>
106+
88107
And your Flutter module also depends on
89108
[firebase_crashlytics][] via `pubspec.yaml`:
90109

@@ -104,7 +123,7 @@ firebase_crashlytics v0.1.3's own [Gradle file][]:
104123
105124
dependencies {
106125
107-
implementation("com.crashlytics.sdk.android:crashlytics:2.9.9")
126+
implementation "com.crashlytics.sdk.android:crashlytics:2.9.9"
108127
109128
}
110129
@@ -124,16 +143,35 @@ or implementation breaking changes between the versions.
124143
For example, you might use the new Crashlytics library
125144
in your existing app as follows:
126145

146+
<Tabs key="existing-app-dependencies-2">
147+
<Tab name="Kotlin">
148+
149+
```kotlin title="ExistingApp/app/build.gradle.kts"
150+
151+
dependencies {
152+
153+
implementation("com.crashlytics.sdk.android:crashlytics:2.10.1")
154+
155+
}
156+
157+
```
158+
159+
</Tab>
160+
<Tab name="Groovy">
161+
127162
```groovy title="ExistingApp/app/build.gradle"
128163
129164
dependencies {
130165
131-
implementation("com.google.firebase:firebase-crashlytics:17.0.0-beta03")
166+
implementation "com.google.firebase:firebase-crashlytics:17.0.0-beta03"
132167
133168
}
134169
135170
```
136171

172+
</Tab>
173+
</Tabs>
174+
137175
This approach won't work since there are major API differences
138176
between the Crashlytics' Gradle library version
139177
v17.0.0-beta03 and v2.9.9.

src/content/packages-and-plugins/using-packages.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,31 @@ Gradle build logic instead.
212212
To force the use of `guava` version `28.0`, make the following
213213
changes to the app's `android/build.gradle` file:
214214

215-
```groovy
215+
<Tabs key="android-conflict-resolution">
216+
<Tab name="Kotlin">
217+
218+
```kotlin title="android/app/build.gradle.kts"
219+
configurations.all {
220+
resolutionStrategy {
221+
force("com.google.guava:guava:28.0-android")
222+
}
223+
}
224+
```
225+
226+
</Tab>
227+
<Tab name="Groovy">
228+
229+
```groovy title="android/app/build.gradle"
216230
configurations.all {
217231
resolutionStrategy {
218232
force 'com.google.guava:guava:28.0-android'
219233
}
220234
}
221235
```
222236

237+
</Tab>
238+
</Tabs>
239+
223240
CocoaPods doesn't currently offer dependency
224241
override functionality.
225242

src/content/perf/deferred-components.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,32 @@ Add Play Core to the Android app's
4848
build.gradle dependencies.
4949
In `android/app/build.gradle` add the following:
5050

51-
```groovy
51+
<Tabs key="android-play-core">
52+
<Tab name="Kotlin">
53+
54+
```kotlin title="android/app/build.gradle.kts"
55+
...
56+
dependencies {
57+
...
58+
implementation("com.google.android.play:core:1.8.0")
59+
...
60+
}
61+
```
62+
63+
</Tab>
64+
<Tab name="Groovy">
65+
66+
```groovy title="android/app/build.gradle"
5267
...
5368
dependencies {
5469
...
5570
implementation "com.google.android.play:core:1.8.0"
5671
...
5772
}
5873
```
74+
75+
</Tab>
76+
</Tabs>
5977
</li>
6078

6179
<li>
@@ -558,11 +576,25 @@ defined in the pubspec named, `boxComponent`, `circleComponent`,
558576
and `assetComponent`, ensure that `android/settings.gradle`
559577
contains the following:
560578

561-
```groovy
579+
<Tabs key="android-settings-gradle">
580+
<Tab name="Kotlin">
581+
582+
```kotlin title="android/settings.gradle.kts"
583+
include(":app", ":boxComponent", ":circleComponent", ":assetComponent")
584+
...
585+
```
586+
587+
</Tab>
588+
<Tab name="Groovy">
589+
590+
```groovy title="android/settings.gradle"
562591
include ':app', ':boxComponent', ':circleComponent', ':assetComponent'
563592
...
564593
```
565594

595+
</Tab>
596+
</Tabs>
597+
566598
</li>
567599

568600
<li>

src/content/platform-integration/android/compose-activity.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,26 @@ The first file requiring modifications is `android/app/build.gradle`.
114114

115115
1. Add the following to the existing `android` block:
116116

117+
<Tabs key="android-build-features">
118+
<Tab name="Kotlin">
119+
120+
```kotlin title="android/app/build.gradle.kts"
121+
android {
122+
// Begin adding here
123+
buildFeatures {
124+
compose = true
125+
}
126+
composeOptions {
127+
// https://developer.android.com/jetpack/androidx/releases/compose-kotlin
128+
kotlinCompilerExtensionVersion = "1.4.8"
129+
}
130+
// End adding here
131+
}
132+
```
133+
134+
</Tab>
135+
<Tab name="Groovy">
136+
117137
```groovy title="android/app/build.gradle"
118138
android {
119139
// Begin adding here
@@ -128,6 +148,9 @@ The first file requiring modifications is `android/app/build.gradle`.
128148
}
129149
```
130150

151+
</Tab>
152+
</Tabs>
153+
131154
Visit the [developer.android.com][] link in the code snippet and
132155
adjust `kotlinCompilerExtensionVersion`, as necessary.
133156
You should only need to do this if you
@@ -138,6 +161,34 @@ The first file requiring modifications is `android/app/build.gradle`.
138161

139162
2. Next, add the following block at the bottom of the file, at the root level:
140163

164+
<Tabs key="android-dependencies">
165+
<Tab name="Kotlin">
166+
167+
```kotlin title="android/app/build.gradle.kts"
168+
dependencies {
169+
implementation("androidx.core:core-ktx:1.10.1")
170+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
171+
implementation("androidx.activity:activity-compose")
172+
implementation(platform("androidx.compose:compose-bom:2024.06.00"))
173+
implementation("androidx.compose.ui:ui")
174+
implementation("androidx.compose.ui:ui-graphics")
175+
implementation("androidx.compose.ui:ui-tooling-preview")
176+
implementation("androidx.compose.material:material")
177+
implementation("androidx.compose.material3:material3")
178+
testImplementation("junit:junit:4.13.2")
179+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
180+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
181+
androidTestImplementation(platform("androidx.compose:compose-bom:2024.06.00"))
182+
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
183+
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
184+
debugImplementation("androidx.compose.ui:ui-tooling")
185+
debugImplementation("androidx.compose.ui:ui-test-manifest")
186+
}
187+
```
188+
189+
</Tab>
190+
<Tab name="Groovy">
191+
141192
```groovy title="android/app/build.gradle"
142193
dependencies {
143194
implementation("androidx.core:core-ktx:1.10.1")
@@ -155,14 +206,51 @@ The first file requiring modifications is `android/app/build.gradle`.
155206
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
156207
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
157208
debugImplementation("androidx.compose.ui:ui-tooling")
158-
debugImplementation("androidx.compose.ui:ui-test-manifest")
209+
implementation "androidx.core:core-ktx:1.10.1"
210+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
211+
implementation "androidx.activity:activity-compose"
212+
implementation platform("androidx.compose:compose-bom:2024.06.00")
213+
implementation "androidx.compose.ui:ui"
214+
implementation "androidx.compose.ui:ui-graphics"
215+
implementation "androidx.compose.ui:ui-tooling-preview"
216+
implementation "androidx.compose.material:material"
217+
implementation "androidx.compose.material3:material3"
218+
testImplementation "junit:junit:4.13.2"
219+
androidTestImplementation "androidx.test.ext:junit:1.1.5"
220+
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
221+
androidTestImplementation platform("androidx.compose:compose-bom:2023.08.00")
222+
androidTestImplementation "androidx.compose.ui:ui-test-junit4"
223+
debugImplementation "androidx.compose.ui:ui-tooling"
224+
debugImplementation "androidx.compose.ui:ui-test-manifest"
159225
}
160226
```
161227

228+
</Tab>
229+
</Tabs>
230+
162231
The second file requiring modifications is `android/build.gradle`.
163232

164233
1. Add the following buildscript block at the top of the file:
165234

235+
<Tabs key="android-buildscript">
236+
<Tab name="Kotlin">
237+
238+
```kotlin title="android/build.gradle.kts"
239+
buildscript {
240+
dependencies {
241+
// Replace with the latest version.
242+
classpath("com.android.tools.build:gradle:8.1.1")
243+
}
244+
repositories {
245+
google()
246+
mavenCentral()
247+
}
248+
}
249+
```
250+
251+
</Tab>
252+
<Tab name="Groovy">
253+
166254
```groovy title="android/build.gradle"
167255
buildscript {
168256
dependencies {
@@ -176,6 +264,9 @@ The first file requiring modifications is `android/app/build.gradle`.
176264
}
177265
```
178266

267+
</Tab>
268+
</Tabs>
269+
179270
The third file requiring modifications is
180271
`android/app/src/main/AndroidManifest.xml`.
181272

0 commit comments

Comments
 (0)