Status Update
Comments
jg...@google.com <jg...@google.com>
je...@google.com <je...@google.com>
je...@google.com <je...@google.com> #2
it is difficult as we are talking 2 different modules.
artifacts
was never meant to publish things between variants and even less between modules.
what are you trying to get from such a functionality ?
au...@google.com <au...@google.com> #3
If it was purely unrelated modules I would agree with you, however com.android.test
is super tightly linked with the app project it instruments.
Our usecase is to build pairs of APKs needed to be sent to firebase test lab to run the tests. build.gradle links these two projects via targetProjectPath
and it works from gradle, but from the onVariants API there is no way to detect this linkage.
Right now we use a really ugly workaround to make this work that i'd like to get away with.
je...@google.com <je...@google.com> #4
I wonder if we should just do a punch through to give you access to the tested APK rather than the entire artifacts API ?
something like :
onVariants { variant ->
variant.artifacts.get(SingleArtifact.TESTED_APK) // only return something if this is a test-module otherwise null.
}
wdyt ?
au...@google.com <au...@google.com> #5
I only need the artifact directory and the BuiltArtifactsLoader, so if you can get those for me, that works too.
au...@google.com <au...@google.com> #6
This is how we use it now for application projects
au...@google.com <au...@google.com> #7
Note, to work around it we have to poke into internals of AGP APIs.
extensions.findByType(TestAndroidComponentsExtension::class.java)?.apply {
onVariants(selector().all()) { variant ->
tasks.named(
"${AndroidXImplPlugin.GENERATE_TEST_CONFIGURATION_TASK}${variant.name}",
GenerateTestConfigurationTask::class.java
) { task ->
task.appLoader.set(variant.artifacts.getBuiltArtifactsLoader())
// The target app path is defined in the targetProjectPath field in the android
// extension of the test module
val targetProjectPath =
project.extensions.getByType(TestExtension::class.java).targetProjectPath
?: throw IllegalStateException(
"""
Module `$path` does not have a targetProjectPath defined.
"""
.trimIndent()
)
task.outputAppApk.set(outputAppApkFile(variant, targetProjectPath, path))
task.appFileCollection.from(
configurations
.named("${variant.name}TestedApks")
.get()
.incoming
.artifactView {
it.attributes { container ->
container.attribute(
AndroidArtifacts.ARTIFACT_TYPE,
ArtifactType.APK.type
)
}
}
.files
)
}
}
}
having to use
import com.android.build.gradle.internal.attributes.VariantAttr
import com.android.build.gradle.internal.publishing.AndroidArtifacts
import com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactType
au...@google.com <au...@google.com> #8
Any updates here?
je...@google.com <je...@google.com> #9
no news, it's on the backlog though
ak...@google.com <ak...@google.com> #10
Probably we will need something similar for privacy sandbox artifacts as well.
Context: For macrobenchmarks of privacy sandbox projects on Jetpack CI we will need to extract not only test app APK, but also privacy sandbox dependencies (SDKs, splits, etc).
Privacy Sandbox artifacts will be exposed in
je...@google.com <je...@google.com> #11
Amit, looks like we need a more extensible solution than what I suggested in
am...@google.com <am...@google.com> #12
TestExtension now exposes
an...@google.com <an...@google.com> #13
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Ladybug Feature Drop | 2024.2.2 Canary 2
- Android Gradle Plugin 8.8.0-alpha02
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
AGP should expose a BuiltArtifactLoader for target project apk in com.android.test projects.
If we have a project that uses
plugins { id("com.android.test") }
and specifiesit would be great to have an api similar to