From 4792b9e5076450497d3effc6cf582efeb8ccd4c3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 21:37:35 +0000 Subject: [PATCH 1/8] feat: Use Gradle-managed devices for tests This commit configures the project to use Gradle-managed devices for running Android instrumented tests. This automates the creation and management of emulators, simplifying the testing process for both local development and CI. The following changes were made: - Added a `testOptions.managedDevices` block to `sample/build.gradle.kts` to define four Gradle-managed devices. - Device names are dynamically generated based on the API levels from the version catalog. - `pixel2Api*` devices for local testing. - `atdApi*` (AOSP-ATD) devices for CI. - Created two device groups, `localDevices` and `ciDevices`, to run tests on multiple devices in parallel. - Updated the `update.sh` script to use the `localDevicesDebugAndroidTest` task. - Simplified the GitHub Actions workflow in `.github/workflows/build.yml` by removing the manual emulator setup and running the tests on the `ciDevices` group. --- .github/workflows/build.yml | 40 +++++-------------------------------- sample/build.gradle.kts | 39 ++++++++++++++++++++++++++++++++++++ update.sh | 2 +- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9685e73f..bf3232d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,15 +3,11 @@ on: [ push, pull_request ] env: GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false" + jobs: build: name: Build and test runs-on: ubuntu-latest - strategy: - matrix: - api-level: [ 21, 29 ] - target: [ default ] - arch: [ x86_64 ] steps: - uses: actions/checkout@v4 - uses: gradle/actions/wrapper-validation@v4 @@ -20,38 +16,12 @@ jobs: distribution: temurin java-version: 21 - uses: gradle/actions/setup-gradle@v4 - - run: ./gradlew check - - name: AVD cache - uses: actions/cache@v4 - id: avd-cache - with: - path: | - ~/.android/avd/* - ~/.android/adb* - key: avd-${{ matrix.api-level }} - - name: Enable KVM group perms + - name: Enable KVM run: | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm - - name: Create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ matrix.api-level }} - target: ${{ matrix.target }} - arch: ${{ matrix.arch }} - force-avd-creation: false - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - disable-animations: false - script: echo "Generated AVD snapshot for caching." + - name: Run checks + run: ./gradlew check - name: Run integration tests - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ matrix.api-level }} - target: ${{ matrix.target }} - arch: ${{ matrix.arch }} - force-avd-creation: false - emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - disable-animations: true - script: ./gradlew connectedCheck + run: ./gradlew ciDevicesDebugAndroidTest --info diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index b0c7f8cf..256eb847 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -44,6 +44,45 @@ android { storeFile = rootProject.file("debug.keystore") } } + + testOptions { + val minSdk = libs.versions.minSdkSample.get().toInt() + val targetSdk = libs.versions.targetSdk.get().toInt() + managedDevices { + devices { + create("pixel2Api$minSdk") { + device = "Pixel 2" + apiLevel = minSdk + systemImageSource = "aosp" + } + create("pixel2Api$targetSdk") { + device = "Pixel 2" + apiLevel = targetSdk + systemImageSource = "aosp" + } + create("atdApi$minSdk") { + device = "Pixel 2" + apiLevel = minSdk + systemImageSource = "aosp-atd" + } + create("atdApi$targetSdk") { + device = "Pixel 2" + apiLevel = targetSdk + systemImageSource = "aosp-atd" + } + } + groups { + register("localDevices") { + targetDevices.add(devices.getByName("pixel2Api$minSdk")) + targetDevices.add(devices.getByName("pixel2Api$targetSdk")) + } + register("ciDevices") { + targetDevices.add(devices.getByName("atdApi$minSdk")) + targetDevices.add(devices.getByName("atdApi$targetSdk")) + } + } + } + } } dependencies { diff --git a/update.sh b/update.sh index 45773ed7..9325c439 100755 --- a/update.sh +++ b/update.sh @@ -162,7 +162,7 @@ git checkout -q "v${NEXT_VERSION}" echo "Building the release..." ./gradlew clean build > /dev/null echo "Running tests..." -./gradlew connectedCheck > /dev/null +./gradlew localDevicesDebugAndroidTest > /dev/null echo "Uploading artifacts..." ./gradlew publishAggregationToCentralPortal > /dev/null From 8599769b443c75bb068cb9b9dcba02159cc48fb0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 2 Sep 2025 21:46:36 +0000 Subject: [PATCH 2/8] feat: Use Gradle-managed devices for tests This commit configures the project to use Gradle-managed devices for running Android instrumented tests. This automates the creation and management of emulators, simplifying the testing process for both local development and CI. The following changes were made: - Added a `testOptions.managedDevices` block to `sample/build.gradle.kts` to define four Gradle-managed devices using the non-deprecated `localDevices` container. - Device names are now dynamically generated based on the API levels from the version catalog. - `pixel2Api*` devices for local testing. - `atdApi*` (AOSP-ATD) devices for CI. - Created two device groups, `localDevices` and `ciDevices`, to run tests on multiple devices in parallel. - Updated the `update.sh` script to use the `localDevicesDebugAndroidTest` task. - Simplified the GitHub Actions workflow in `.github/workflows/build.yml` by removing the manual emulator setup and running the tests on the `ciDevices` group. --- sample/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 256eb847..e5ca87b8 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -49,7 +49,7 @@ android { val minSdk = libs.versions.minSdkSample.get().toInt() val targetSdk = libs.versions.targetSdk.get().toInt() managedDevices { - devices { + localDevices { create("pixel2Api$minSdk") { device = "Pixel 2" apiLevel = minSdk From 1fc24978b2bfacab80ecf0f514f508c9c79f0adc Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Wed, 3 Sep 2025 01:00:29 +0300 Subject: [PATCH 3/8] Support legacy devices in GMD --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index cc6563dc..e5cf2e96 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,4 @@ android.useAndroidX=true +android.experimental.testOptions.managedDevices.allowOldApiLevelDevices=true org.gradle.jvmargs=-Xmx1536m From 94b1845248c0f0a7119135fc5b46f16b9628c92e Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Wed, 3 Sep 2025 01:06:02 +0300 Subject: [PATCH 4/8] Fix running test on API level 21 --- sample/build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index e5ca87b8..36228a2e 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -63,7 +63,8 @@ android { create("atdApi$minSdk") { device = "Pixel 2" apiLevel = minSdk - systemImageSource = "aosp-atd" + // ATD image doesn't exist for API level 21 + systemImageSource = "aosp" } create("atdApi$targetSdk") { device = "Pixel 2" From 0d60aed117a86433f44164b5b55f39830d659398 Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Wed, 3 Sep 2025 01:11:54 +0300 Subject: [PATCH 5/8] Don't use deprecated devices property in GMD --- sample/build.gradle.kts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 36228a2e..6a65b60b 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -74,12 +74,12 @@ android { } groups { register("localDevices") { - targetDevices.add(devices.getByName("pixel2Api$minSdk")) - targetDevices.add(devices.getByName("pixel2Api$targetSdk")) + targetDevices.add(allDevices.getByName("pixel2Api$minSdk")) + targetDevices.add(allDevices.getByName("pixel2Api$targetSdk")) } register("ciDevices") { - targetDevices.add(devices.getByName("atdApi$minSdk")) - targetDevices.add(devices.getByName("atdApi$targetSdk")) + targetDevices.add(allDevices.getByName("atdApi$minSdk")) + targetDevices.add(allDevices.getByName("atdApi$targetSdk")) } } } From 60b19ed0da257a6b05823af821e5bbba969ee39f Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Wed, 3 Sep 2025 01:15:24 +0300 Subject: [PATCH 6/8] Use arm64 runner --- .github/workflows/build.yml | 2 +- sample/build.gradle.kts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf3232d9..f28a3958 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ env: jobs: build: name: Build and test - runs-on: ubuntu-latest + runs-on: ubuntu-latest-arm64 steps: - uses: actions/checkout@v4 - uses: gradle/actions/wrapper-validation@v4 diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 6a65b60b..6cdb41af 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -63,8 +63,7 @@ android { create("atdApi$minSdk") { device = "Pixel 2" apiLevel = minSdk - // ATD image doesn't exist for API level 21 - systemImageSource = "aosp" + systemImageSource = "aosp-atd" } create("atdApi$targetSdk") { device = "Pixel 2" From 820fb6d6742a7a66e4e88686f7c6ab1e9db816db Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Wed, 3 Sep 2025 01:24:52 +0300 Subject: [PATCH 7/8] Use a proper name for the arm64 runner --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f28a3958..8722c214 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ env: jobs: build: name: Build and test - runs-on: ubuntu-latest-arm64 + runs-on: ubuntu-24.04-arm steps: - uses: actions/checkout@v4 - uses: gradle/actions/wrapper-validation@v4 From a4a5b18ddf1b113b66a487cf8db3c2053c8fcc54 Mon Sep 17 00:00:00 2001 From: Michael Rozumyanskiy Date: Wed, 3 Sep 2025 01:28:06 +0300 Subject: [PATCH 8/8] There's no kvm on the arm64 runner --- .github/workflows/build.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8722c214..fe705b35 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,11 +16,6 @@ jobs: distribution: temurin java-version: 21 - uses: gradle/actions/setup-gradle@v4 - - name: Enable KVM - run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm - name: Run checks run: ./gradlew check - name: Run integration tests