-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run android emulator on ubuntu build agent.
gradle-managed-devices
…
…is used instead of reactivecircus/android-emulator-runner GitHub action task (#524)
- Loading branch information
1 parent
096f468
commit 90fba35
Showing
24 changed files
with
228 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Project exclude paths | ||
/.gradle/ | ||
/**/.gradle/ | ||
/**/build/ | ||
/.idea/ | ||
local.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.android.gradle.plugin) | ||
compileOnly(libs.gson) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
dependencyResolutionManagement { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
convention-plugin-test-option/src/main/kotlin/EmulatorJobsMatrix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import com.google.gson.GsonBuilder | ||
import org.gradle.api.Project | ||
import java.io.File | ||
import java.util.Properties | ||
|
||
class EmulatorJobsMatrix { | ||
|
||
private val gson by lazy { | ||
GsonBuilder() | ||
.disableHtmlEscaping() | ||
.setPrettyPrinting() | ||
.create() | ||
} | ||
|
||
fun createMatrixJsonFile(rootProject: Project) { | ||
val taskList = getTaskList(rootProject = rootProject).map { it.joinToString(separator = " ") } | ||
val matrix = mapOf("gradle_tasks" to taskList) | ||
val jsonText = gson.toJson(matrix) | ||
rootProject.layout.buildDirectory.asFile.get().also { buildDir -> | ||
buildDir.mkdirs() | ||
File(buildDir, "emulator_jobs_matrix.json").writeText(jsonText) | ||
} | ||
} | ||
|
||
fun getTaskList(rootProject: Project): List<List<String>> = | ||
rootProject.subprojects.filter { subProject -> | ||
File(subProject.projectDir, "src${File.separator}androidInstrumentedTest").exists() | ||
}.map { subProject -> | ||
"${subProject.path}:gradleManagedDeviceDebugAndroidTest" | ||
}.map { taskName -> | ||
mutableListOf(taskName).also { | ||
it.add("--no-parallel") | ||
it.add("--max-workers=1") | ||
it.add("-Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect") | ||
it.add("-Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true") | ||
}.also { | ||
if (!true.toString().equals(other = System.getenv("CI"), ignoreCase = true)) { | ||
it.add("--enable-display") | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun getAndroidSdkPath(rootDir: File): String? = | ||
Properties().apply { | ||
val propertiesFile = File(rootDir, "local.properties") | ||
if (propertiesFile.exists()) { | ||
load(propertiesFile.inputStream()) | ||
} | ||
}.getProperty("sdk.dir").let { propertiesSdkDirPath -> | ||
(propertiesSdkDirPath ?: System.getenv("ANDROID_HOME")) | ||
} | ||
|
||
fun getSdkmanagerFile(rootDir: File): File? = | ||
getAndroidSdkPath(rootDir = rootDir)?.let { sdkDirPath -> | ||
println("sdkDirPath: $sdkDirPath") | ||
val files = File(sdkDirPath).walk().filter { file -> | ||
file.path.contains("cmdline-tools") && file.path.endsWith("sdkmanager") | ||
} | ||
files.forEach { println("walk: ${it.absolutePath}") } | ||
val sdkmanagerFile = files.firstOrNull() | ||
println("sdkmanagerFile: $sdkmanagerFile") | ||
sdkmanagerFile | ||
} |
32 changes: 32 additions & 0 deletions
32
convention-plugin-test-option/src/main/kotlin/TestOptionsConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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" | ||
require64Bit = true | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
convention-plugin-test-option/src/main/kotlin/testOptionsConvention.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
plugins { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.