Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Switch GMD to use a convention plugin

Alex Vanyo6146dd55769b
diff --git a/.github/workflows/AndroidCIWithGmd.yaml b/.github/workflows/AndroidCIWithGmd.yaml
index 6721d3aa0..eb890c4d5 100644
--- a/.github/workflows/AndroidCIWithGmd.yaml
+++ b/.github/workflows/AndroidCIWithGmd.yaml
@@ -10,6 +10,9 @@ jobs:
android-ci:
runs-on: macos-12
+ strategy:
+ matrix:
+ device-config: [ "pixel4api30aospatd" ]
steps:
- uses: actions/setup-java@v3
@@ -23,7 +26,7 @@ jobs:
- name: Run instrumented tests with GMD
run: ./gradlew cleanManagedDevices --unused-only &&
- ./gradlew pixel4api30DemoDebugAndroidTest -Dorg.gradle.workers.max=1
+ ./gradlew ${{ matrix.device-config }}DemoDebugAndroidTest -Dorg.gradle.workers.max=1
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true --info
- name: Upload test reports
diff --git a/.run/Generate Demo Baseline Profile.run.xml b/.run/Generate Demo Baseline Profile.run.xml
index 4c34e5a76..a4b0de892 100644
--- a/.run/Generate Demo Baseline Profile.run.xml
+++ b/.run/Generate Demo Baseline Profile.run.xml
@@ -34,7 +34,7 @@
</option>
<option name="taskNames">
<list>
- <option value=":benchmark:pixel6Api31DemoBenchmarkAndroidTest" />
+ <option value=":benchmark:pixel6Api31atdDemoBenchmarkAndroidTest" />
<option value="--rerun" />
<option value="--enable-display" />
</list>
diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts
index ba04eda23..9af89d98d 100644
--- a/benchmarks/build.gradle.kts
+++ b/benchmarks/build.gradle.kts
@@ -65,19 +65,6 @@ android {
targetProjectPath = ":app"
experimentalProperties["android.experimental.self-instrumenting"] = true
-
- testOptions {
- // TODO: Convert it as a convention plugin once Flamingo goes out (https://github.com/android/nowinandroid/issues/523)
- managedDevices {
- devices {
- create<ManagedVirtualDevice>("pixel6Api31") {
- device = "Pixel 6"
- apiLevel = 31
- systemImageSource = "aosp"
- }
- }
- }
- }
}
dependencies {
diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
index 612eb6ad4..6bc5f9f9e 100644
--- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
+++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
@@ -17,6 +17,7 @@
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.api.dsl.ApplicationExtension
import com.google.samples.apps.nowinandroid.configureFlavors
+import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
import com.google.samples.apps.nowinandroid.configurePrintApksTask
import org.gradle.api.Plugin
@@ -35,6 +36,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 33
configureFlavors(this)
+ configureGradleManagedDevices(this)
}
extensions.configure<ApplicationAndroidComponentsExtension> {
configurePrintApksTask(this)
diff --git a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt
index a637b78c0..0c71d9d4c 100644
--- a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt
+++ b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt
@@ -14,7 +14,9 @@
* limitations under the License.
*/
+import com.android.build.api.dsl.ApplicationExtension
import com.android.build.gradle.LibraryExtension
+import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
@@ -35,6 +37,7 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
testInstrumentationRunner =
"com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner"
}
+ configureGradleManagedDevices(this)
}
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt
index f7d6d184a..842873bae 100644
--- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt
+++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt
@@ -18,6 +18,7 @@ import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.gradle.LibraryExtension
import com.google.samples.apps.nowinandroid.configureFlavors
+import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
import com.google.samples.apps.nowinandroid.configurePrintApksTask
import org.gradle.api.Plugin
@@ -40,6 +41,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 33
configureFlavors(this)
+ configureGradleManagedDevices(this)
}
extensions.configure<LibraryAndroidComponentsExtension> {
configurePrintApksTask(this)
diff --git a/build-logic/convention/src/main/kotlin/AndroidTestConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidTestConventionPlugin.kt
index 8d446505c..286871010 100644
--- a/build-logic/convention/src/main/kotlin/AndroidTestConventionPlugin.kt
+++ b/build-logic/convention/src/main/kotlin/AndroidTestConventionPlugin.kt
@@ -15,6 +15,7 @@
*/
import com.android.build.gradle.TestExtension
+import com.google.samples.apps.nowinandroid.configureGradleManagedDevices
import com.google.samples.apps.nowinandroid.configureKotlinAndroid
import org.gradle.api.Plugin
import org.gradle.api.Project
@@ -31,6 +32,7 @@ class AndroidTestConventionPlugin : Plugin<Project> {
extensions.configure<TestExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 31
+ configureGradleManagedDevices(this)
}
}
}
diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt
new file mode 100644
index 000000000..f16344088
--- /dev/null
+++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/GradleManagedDevices.kt
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.samples.apps.nowinandroid
+
+import com.android.build.api.dsl.CommonExtension
+import com.android.build.api.dsl.ManagedVirtualDevice
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.invoke
+import java.util.Locale
+
+/**
+ * Configure project for Gradle managed devices
+ */
+internal fun configureGradleManagedDevices(
+ commonExtension: CommonExtension<*, *, *, *>,
+) {
+ val deviceConfigs = listOf(
+ DeviceConfig("Pixel 4", 30, "aosp-atd"),
+ DeviceConfig("Pixel 6", 31, "aosp")
+ )
+
+ commonExtension.testOptions {
+ managedDevices {
+ devices {
+ deviceConfigs.forEach { deviceConfig ->
+ maybeCreate(deviceConfig.taskName, ManagedVirtualDevice::class.java).apply {
+ device = deviceConfig.device
+ apiLevel = deviceConfig.apiLevel
+ systemImageSource = deviceConfig.systemImageSource
+ }
+ }
+ }
+ }
+ }
+}
+
+private data class DeviceConfig(
+ val device: String,
+ val apiLevel: Int,
+ val systemImageSource: String,
+) {
+ val taskName = buildString {
+ append(device.toLowerCase(Locale.ROOT).replace(" ", ""))
+ append("api")
+ append(apiLevel.toString())
+ append(systemImageSource.replace("-", ""))
+ }
+}
diff --git a/feature/bookmarks/build.gradle.kts b/feature/bookmarks/build.gradle.kts
index 2bbeec9a1..5dfd7e014 100644
--- a/feature/bookmarks/build.gradle.kts
+++ b/feature/bookmarks/build.gradle.kts
@@ -24,20 +24,6 @@ plugins {
android {
namespace = "com.google.samples.apps.nowinandroid.feature.bookmarks"
-
- testOptions {
- // TODO: Convert it as a convention plugin once Flamingo goes out (https://github.com/android/nowinandroid/issues/523)
- managedDevices {
- devices {
- maybeCreate<ManagedVirtualDevice>("pixel4api30").apply {
- device = "Pixel 4"
- apiLevel = 30
- // ATDs currently support only API level 30.
- systemImageSource = "aosp-atd"
- }
- }
- }
- }
}
dependencies {
diff --git a/feature/foryou/build.gradle.kts b/feature/foryou/build.gradle.kts
index 59e0cc904..ed7be27dc 100644
--- a/feature/foryou/build.gradle.kts
+++ b/feature/foryou/build.gradle.kts
@@ -24,20 +24,6 @@ plugins {
android {
namespace = "com.google.samples.apps.nowinandroid.feature.foryou"
-
- testOptions {
- // TODO: Convert it as a convention plugin once Flamingo goes out (https://github.com/android/nowinandroid/issues/523)
- managedDevices {
- devices {
- maybeCreate<ManagedVirtualDevice>("pixel4api30").apply {
- device = "Pixel 4"
- apiLevel = 30
- // ATDs currently support only API level 30.
- systemImageSource = "aosp-atd"
- }
- }
- }
- }
}
dependencies {
diff --git a/feature/interests/build.gradle.kts b/feature/interests/build.gradle.kts
index 8fd9dcd8d..12b3074e4 100644
--- a/feature/interests/build.gradle.kts
+++ b/feature/interests/build.gradle.kts
@@ -23,18 +23,4 @@ plugins {
}
android {
namespace = "com.google.samples.apps.nowinandroid.feature.interests"
-
- testOptions {
- // TODO: Convert it as a convention plugin once Flamingo goes out (https://github.com/android/nowinandroid/issues/523)
- managedDevices {
- devices {
- maybeCreate<ManagedVirtualDevice>("pixel4api30").apply {
- device = "Pixel 4"
- apiLevel = 30
- // ATDs currently support only API level 30.
- systemImageSource = "aosp-atd"
- }
- }
- }
- }
}
diff --git a/feature/settings/build.gradle.kts b/feature/settings/build.gradle.kts
index 41dee24dc..8d1d846da 100644
--- a/feature/settings/build.gradle.kts
+++ b/feature/settings/build.gradle.kts
@@ -24,18 +24,4 @@ plugins {
android {
namespace = "com.google.samples.apps.nowinandroid.feature.settings"
-
- testOptions {
- // TODO: Convert it as a convention plugin once Flamingo goes out (https://github.com/android/nowinandroid/issues/523)
- managedDevices {
- devices {
- maybeCreate<ManagedVirtualDevice>("pixel4api30").apply {
- device = "Pixel 4"
- apiLevel = 30
- // ATDs currently support only API level 30.
- systemImageSource = "aosp-atd"
- }
- }
- }
- }
}
diff --git a/feature/topic/build.gradle.kts b/feature/topic/build.gradle.kts
index 48e2563f8..6bacd8343 100644
--- a/feature/topic/build.gradle.kts
+++ b/feature/topic/build.gradle.kts
@@ -24,20 +24,6 @@ plugins {
android {
namespace = "com.google.samples.apps.nowinandroid.feature.topic"
-
- testOptions {
- // TODO: Convert it as a convention plugin once Flamingo goes out (https://github.com/android/nowinandroid/issues/523)
- managedDevices {
- devices {
- maybeCreate<ManagedVirtualDevice>("pixel4api30").apply {
- device = "Pixel 4"
- apiLevel = 30
- // ATDs currently support only API level 30.
- systemImageSource = "aosp-atd"
- }
- }
- }
- }
}
dependencies {