Skip to content

Commit

Permalink
Run android emulator on ubuntu build agent. gradle-managed-devices
Browse files Browse the repository at this point in the history
…is used instead of reactivecircus/android-emulator-runner GitHub action task
  • Loading branch information
siarhei-luskanau committed Jun 16, 2024
1 parent 3a994aa commit 008bc8b
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 118 deletions.
30 changes: 7 additions & 23 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ on:

jobs:
build-android:
runs-on: macos-13
runs-on: ubuntu-latest
strategy:
matrix:
api-level: [ 34 ]
steps:
- uses: actions/checkout@v3
- name: Enable KVM group perms
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: Setup test environment
uses: ./.github/actions/setup_test_action
- name: AVD cache
Expand All @@ -25,29 +30,8 @@ jobs:
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}-${{ runner.os }}-${{ runner.arch }}
- 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 }}
arch: x86_64
target: google_apis
avd-name: pixel6_API${{ matrix.api-level }}
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 Android Instrumented Tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
arch: x86_64
target: google_apis
avd-name: pixel6_API${{ matrix.api-level }}
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 connectedAndroidTest
run: ./gradlew gradleManagedDeviceDebugAndroidTest
- name: Upload Android test artifact
uses: actions/upload-artifact@v3
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Project exclude paths
/.gradle/
/**/.gradle/
/**/build/
/.idea/
local.properties
Expand Down
7 changes: 7 additions & 0 deletions convention-plugin-test-option/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

dependencies {
compileOnly(libs.android.gradle.plugin)
}
19 changes: 19 additions & 0 deletions convention-plugin-test-option/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
}

dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
31 changes: 31 additions & 0 deletions convention-plugin-test-option/src/main/kotlin/TestOptionsConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import com.android.build.api.dsl.ManagedVirtualDevice
import com.android.build.api.dsl.TestOptions
import org.gradle.kotlin.dsl.create

fun TestOptions.configureTestOptions() {
unitTests {
isIncludeAndroidResources = true
all { test: org.gradle.api.tasks.testing.Test ->
test.testLogging {
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
events = setOf(
org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED,
org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED,
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT,
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR,
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
)
}
}
}
animationsDisabled = true
emulatorSnapshots {
enableForTestFailures = false
}
managedDevices.devices.create<ManagedVirtualDevice>("gradleManagedDevice") {
device = "Pixel 2"
apiLevel = 33
systemImageSource = "google-atd"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins {
}
8 changes: 2 additions & 6 deletions firebase-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree

/*
Expand All @@ -11,6 +10,7 @@ plugins {
id("com.android.library")
kotlin("native.cocoapods")
kotlin("multiplatform")
id("testOptionsConvention")
}

android {
Expand All @@ -30,11 +30,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand Down
21 changes: 2 additions & 19 deletions firebase-auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("native.cocoapods")
//id("com.quittle.android-emulator") version "0.2.0"
id("testOptionsConvention")
}

android {
Expand All @@ -30,11 +30,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand All @@ -45,19 +41,6 @@ android {
}
}

// Optional configuration
//androidEmulator {
// emulator {
// name("givlive_emulator")
// sdkVersion(28)
// abi("x86_64")
// includeGoogleApis(true) // Defaults to false
//
// }
// headless(false)
// logEmulatorOutput(false)
//}

val supportIosTarget = project.property("skipIosTarget") != "true"

kotlin {
Expand Down
7 changes: 2 additions & 5 deletions firebase-common-internal/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
id("testOptionsConvention")
}

android {
Expand All @@ -28,11 +29,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()

packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
Expand Down
7 changes: 2 additions & 5 deletions firebase-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("plugin.serialization")
id("testOptionsConvention")
}

android {
Expand All @@ -28,11 +29,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()

packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
Expand Down
21 changes: 2 additions & 19 deletions firebase-config/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("native.cocoapods")
//id("com.quittle.android-emulator") version "0.2.0"
id("testOptionsConvention")
}

android {
Expand All @@ -30,11 +30,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand All @@ -45,19 +41,6 @@ android {
}
}

// Optional configuration
//androidEmulator {
// emulator {
// name("givlive_emulator")
// sdkVersion(28)
// abi("x86_64")
// includeGoogleApis(true) // Defaults to false
//
// }
// headless(false)
// logEmulatorOutput(false)
//}

val supportIosTarget = project.property("skipIosTarget") != "true"

kotlin {
Expand Down
7 changes: 2 additions & 5 deletions firebase-crashlytics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
id("com.android.library")
kotlin("multiplatform")
kotlin("native.cocoapods")
id("testOptionsConvention")
}

android {
Expand All @@ -30,11 +31,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Copyright (c) 2020 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
*/
Expand Down
7 changes: 2 additions & 5 deletions firebase-database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
kotlin("native.cocoapods")
kotlin("multiplatform")
kotlin("plugin.serialization")
id("testOptionsConvention")
}

repositories {
Expand All @@ -35,11 +36,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand Down
7 changes: 2 additions & 5 deletions firebase-firestore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
kotlin("native.cocoapods")
kotlin("multiplatform")
kotlin("plugin.serialization")
id("testOptionsConvention")
}

android {
Expand All @@ -31,11 +32,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand Down
7 changes: 2 additions & 5 deletions firebase-functions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
id("com.android.library")
kotlin("native.cocoapods")
kotlin("multiplatform")
id("testOptionsConvention")
}

android {
Expand All @@ -29,11 +30,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand Down
7 changes: 2 additions & 5 deletions firebase-installations/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
id("com.android.library")
kotlin("native.cocoapods")
kotlin("multiplatform")
id("testOptionsConvention")
}

android {
Expand All @@ -29,11 +30,7 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}

testOptions {
unitTests.apply {
isIncludeAndroidResources = true
}
}
testOptions.configureTestOptions()
packaging {
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
resources.pickFirsts.add("META-INF/AL2.0")
Expand Down
Loading

0 comments on commit 008bc8b

Please sign in to comment.