Fixed
Status Update
Comments
pa...@google.com <pa...@google.com>
tn...@google.com <tn...@google.com>
an...@google.com <an...@google.com> #3
OP and +1's, please take a look at the following proposal and let us know if it would meet your needs.
Proposal:
Instead of exposing source set names, AGP could add APIs to support this specific use case. AGP would handle creating the configurations, etc.
interface AndroidComponentsExtension {
/**
* Adds a custom configuration for each source set.
*
* The [suffix] parameter determines the naming convention for the generated configurations.
* For example, if [suffix] is "custom", the generated configurations would be "custom",
* "debugCustom", "releaseCustom", "testCustom", etc.
*
* Under the hood, this API:
* 1. Creates a configuration for each source set.
* 2. Creates resolvable configurations for each component.
* 3. Ensures that each resolvable configuration extends the corresponding source set
* configurations.
*
* Each component's corresponding resolvable configuration can be accessed via
* [Component.getResolvableConfiguration].
*
* Example usage:
* ```kotlin
* androidComponents {
* addSourceSetConfigurations("foo")
* onVariants { variant ->
* val resolvableConfiguration = variant.getResolvableConfiguration("foo")
* variant.nestedComponents.forEach { component ->
* val nestedResolvableConfiguration =
* component.getResolvableConfiguration("foo")
* }
* }
* }
* ```
*
* @param suffix the suffix to append to the generated configuration names.
*/
@Incubating
fun addSourceSetConfigurations(suffix: String)
}
interface Component {
/**
* Access to the component's resolvable configuration corresponding to the source set
* configurations added via [AndroidComponentsExtension.addSourceSetConfigurations].
*
* Example usage:
* ```kotlin
* androidComponents {
* addSourceSetConfigurations("foo")
* onVariants { variant ->
* val resolvableConfiguration = variant.getResolvableConfiguration("foo")
* variant.nestedComponents.forEach { component ->
* val nestedResolvableConfiguration =
* component.getResolvableConfiguration("foo")
* }
* }
* }
* ```
*
* The returned [Configuration] should not be resolved until execution time.
*/
@Incubating
fun getResolvableConfiguration(sourceSetConfigurationsAffix: String): Configuration
}
Under the hood, AGP would (1) create configurations per source set, (2) create a resolvable configuration per component, and (3) make each resolvable configuration extend from the corresponding source set configurations.
Example Usage:
androidComponents {
addSourceSetConfigurations(suffix = "pluginDeps")
onVariants { variant ->
val variantResolvableConfiguration = variant.getResolvableConfiguration("pluginDeps")
// ...
variant.nestedComponents.forEach { component ->
val nestedResolvableConfiguration = component.getResolvableConfiguration("pluginDeps")
// ...
}
}
}
(Edited Jan 8th, 2025 to reflect final APIs)
Description
Use case: I have an instrumentation test I want to only run on devices with a particular SDK extension.
I first looked to see if there's a version of b/257429573
@SdkSuppress
which supports extensions. It seems there isn't:So I adopted the suggested approach from that bug: Use
@RequiresExtension
and anassumeTrue
call in an@Before
method.But lint complains at my usage of
@RequiresExtension
(see screenshot) and says:Which I can't do, because
@SdkSuppress
doesn't support filtering by SDK extension.IMO ideally
@SdkSuppress
would support SDK extensions (or an equivalent annotation would be created). But until then, can we stop lint from asking for the impossible?