From 50baac3403a633a60d704af81ff142a5cc1409fa Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 21 Sep 2024 04:46:58 +0300 Subject: [PATCH] Fix using universal apk when abi-splits are present (#3) * fix failing to use universalApk when abi-splits are present --------- Co-authored-by: Vlad Krasnikov --- .../gradle/task/GenerateMarathonfileTask.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/GenerateMarathonfileTask.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/GenerateMarathonfileTask.kt index c630960..bf119e4 100644 --- a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/GenerateMarathonfileTask.kt +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/gradle/task/GenerateMarathonfileTask.kt @@ -1,6 +1,7 @@ package com.malinskiy.marathon.gradle.task import com.android.build.api.variant.BuiltArtifacts +import com.android.build.api.variant.VariantOutputConfiguration import com.malinskiy.marathon.config.serialization.ConfigurationFactory import com.malinskiy.marathon.config.vendor.android.AndroidTestBundleConfiguration import com.malinskiy.marathon.gradle.GradleAndroidTestBundle @@ -83,19 +84,19 @@ open class GenerateMarathonfileTask @Inject constructor(objects: ObjectFactory) return bundles.map { when(it) { is GradleAndroidTestBundle.ApplicationWithTest -> { - val artifactLoader = it.artifactLoader.get() - val artifacts: BuiltArtifacts = + val artifactLoader = it.artifactLoader.get() + val artifacts: BuiltArtifacts = artifactLoader.load(it.apkFolder.get()) ?: throw RuntimeException("No application artifact found") - when { - artifacts.elements.size > 1 -> throw UnsupportedOperationException( - "The Marathon plugin does not support abi splits for app APKs, " + - "but supports testing via a universal APK. " - + "Add the flag \"universalApk true\" in the android.splits.abi configuration." - ) - - artifacts.elements.isEmpty() -> throw UnsupportedOperationException("No artifacts for variant $flavorName") - } - val application = File(artifacts.elements.first().outputFile) + val validArtifact = artifacts.elements.find { builtArtifact -> + builtArtifact.outputType == VariantOutputConfiguration.OutputType.SINGLE // when there are no splits + } ?: artifacts.elements.find { builtArtifact -> + builtArtifact.outputType == VariantOutputConfiguration.OutputType.UNIVERSAL // when universal apk is present + } ?: throw UnsupportedOperationException( + "The Marathon plugin does not support abi splits for app APKs, " + + "but supports testing via a universal APK. " + + "Add the flag \"universalApk true\" in the android.splits.abi configuration." + ) + val application = File(validArtifact.outputFile) val testArtifactsLoader = it.testArtifactLoader.get() val testArtifacts = testArtifactsLoader.load(it.testApkFolder.get()) ?: throw RuntimeException("No test artifacts for variant $flavorName")