Skip to content

Commit 194f04e

Browse files
juangardi21Copilot
andcommitted
Fix applicationId to use androidTest variant for correct device path
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6eec27b commit 194f04e

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

include-build/gradle-plugin/src/main/java/com/telefonica/androidsnaptesting/AndroidSnaptestingPlugin.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import java.io.File
1414
class AndroidSnaptestingPlugin : Plugin<Project> {
1515

1616
override fun apply(project: Project) {
17-
// Collect applicationId per test-variant name at configuration time using the new variant API.
18-
// onVariants runs during project configuration, before afterEvaluate.
1917
val applicationIds = mutableMapOf<String, Provider<String>>()
2018

2119
project.extensions.findByType(ApplicationAndroidComponentsExtension::class.java)
2220
?.onVariants { variant ->
23-
applicationIds["${variant.name}AndroidTest"] = variant.applicationId
21+
variant.androidTest?.let { androidTest ->
22+
applicationIds["${variant.name}AndroidTest"] = androidTest.applicationId
23+
}
2424
}
2525

2626
project.afterEvaluate {

include-build/gradle-plugin/src/main/java/com/telefonica/androidsnaptesting/DeviceFileManager.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ class DeviceFileManager(
6464
withConnectedDevices { devices ->
6565
devices.forEach { device ->
6666
val serial = device.serialNumber
67-
// List files in the remote folder; ignore errors if the folder doesn't exist yet
68-
val lsResult = runAdbCapture(serial, "shell", "ls", remotePath)
67+
val lsResult = runAdbCapture(serial, "shell", "ls", remotePath, logErrors = false)
6968
val fileNames = lsResult.output.lines()
7069
.map { it.trim() }
7170
.filter { it.isNotBlank() && !it.startsWith("ls:") && !it.contains("No such file") }
72-
// Pull each file to the local destination
7371
fileNames.forEach { fileName ->
7472
runAdb(serial, "pull", "$remotePath/$fileName", "$destinationPath/$fileName")
7573
}
@@ -86,6 +84,7 @@ class DeviceFileManager(
8684
serial: String,
8785
vararg args: String,
8886
throwOnError: Boolean = false,
87+
logErrors: Boolean = true,
8988
): AdbResult {
9089
val command = buildList {
9190
add(adbExecutablePath)
@@ -104,13 +103,13 @@ class DeviceFileManager(
104103
if (!finished || exitCode != 0) {
105104
val message = "ADB command failed: ${command.joinToString(" ")}\nExit code: $exitCode\nOutput: $output\nError: $error"
106105
if (throwOnError) throw RuntimeException(message)
107-
else println(message)
106+
else if (logErrors) println(message)
108107
}
109108
return AdbResult(output, error, exitCode)
110109
} catch (e: Exception) {
111110
val message = "Exception running ADB command: ${command.joinToString(" ")}\n${e.message}"
112111
if (throwOnError) throw RuntimeException(message, e)
113-
else println(message)
112+
else if (logErrors) println(message)
114113
return AdbResult("", e.message ?: "", -1)
115114
}
116115
}

0 commit comments

Comments
 (0)