Component

Added in 7.0.0

interface Component : ComponentIdentity

Known direct subclasses
TestComponent

Model for test components that contains build-time properties.

TestFixtures

Model for Test Fixtures components that contains build-time properties

Variant

Model for variant components that only contains build-time properties

Known indirect subclasses
AndroidTest

Model for Android Test components that contains build-time properties

ApplicationVariant

Model for application components that only contains build-time properties.

DynamicFeatureVariant

Model for dynamic feature components that only contains build-time properties.

LibraryVariant

Model for library components that only contains build-time properties.

TestVariant

Model for test components that only contains build-time properties.

UnitTest

This interface is deprecated. Use the com.android.build.api.variant package

UnitTest

Model for Unit Test components that contains build-time properties


Model for components that only contains build-time properties

Components can be APKs, AARs, test APKs, unit tests, test fixtures, ...

This is the parent interface for all components. From there, there is a first fork, via Variant which are production build output (APKs, AARs), and TestComponent that are test components. TestFixtures is another separate component. See these types for more information.

See Variant for more information on accessing instances of this type.

The properties exposed by this object do not impact the build flow. They are directly set on tasks via org.gradle.api.provider.Property linking.

For example:

tasks.register(...) {
input.set(myComponent.someProperty)
* }

Because links between org.gradle.api.provider.Property objects are lazy, they are ordering-safe and any plugins can set new values or link them into their own tasks in any order.

However, calling org.gradle.api.provider.Property.get during configuration on these properties is not safe as the values could be linked to task output (that requires the task to run).

The object also exposes read-only version of the properties exposed by ComponentBuilder. These will contain the final values set after all AndroidComponentsExtension.beforeVariants callbacks have been executed. It is safe to read these values during configuration time.

See here for more information

Summary

Public functions

Unit

This function is deprecated. Will be removed in v9.0, use the instrumentation block.

Unit
<ParamT : InstrumentationParameters> transformClassesWith(
    classVisitorFactoryImplClass: Class<AsmClassVisitorFactory<ParamT>>,
    scope: InstrumentationScope,
    instrumentationParamsConfig: (ParamT) -> Unit
)

This function is deprecated. Will be removed in v9.0, use the instrumentation block.

Public properties

Configuration

Access to the variant's annotation processor Configuration; for example, the debugAnnotationProcessor Configuration for the debug variant.

Artifacts

Access to the variant's buildable artifacts for build customization.

FileCollection

Access to the variant's compile classpath.

Configuration

Access to the variant's compile Configuration; for example, the debugCompileClasspath Configuration for the debug variant.

Boolean

Whether the produced artifacts will be debuggable

Instrumentation

Access to the variant's instrumentation options.

JavaCompilation

Access to the variant's java compilation options.

LifecycleTasks

Provides access to the LifecycleTasks created for this component.

Provider<String>

The namespace of the generated R and BuildConfig classes.

Configuration

Access to the variant's runtime Configuration; for example, the debugRuntimeClasspath Configuration for the debug variant.

Sources

Access to variant's source files.

Inherited properties

From com.android.build.api.variant.ComponentIdentity
String?

Build type name.

String?

The multi-flavor name of the variant.

String

Component's name.

List<Pair<StringString>>

List of flavor names.

Public functions

setAsmFramesComputationMode

Added in 7.0.0
Deprecated in 7.2.0
fun setAsmFramesComputationMode(mode: FramesComputationMode): Unit

transformClassesWith

Added in 7.0.0
Deprecated in 7.2.0
fun <ParamT : InstrumentationParameters> transformClassesWith(
    classVisitorFactoryImplClass: Class<AsmClassVisitorFactory<ParamT>>,
    scope: InstrumentationScope,
    instrumentationParamsConfig: (ParamT) -> Unit
): Unit

Public properties

annotationProcessorConfiguration

Added in 7.3.0
val annotationProcessorConfigurationConfiguration

Access to the variant's annotation processor Configuration; for example, the debugAnnotationProcessor Configuration for the debug variant.

The returned Configuration should not be resolved until execution time.

artifacts

Added in 7.0.0
val artifactsArtifacts

Access to the variant's buildable artifacts for build customization.

compileClasspath

Added in 7.3.0
val compileClasspathFileCollection

Access to the variant's compile classpath.

The returned FileCollection should not be resolved until execution time.

compileConfiguration

Added in 7.3.0
val compileConfigurationConfiguration

Access to the variant's compile Configuration; for example, the debugCompileClasspath Configuration for the debug variant.

The returned Configuration should not be resolved until execution time.

debuggable

Added in 8.3.2
val debuggableBoolean

Whether the produced artifacts will be debuggable

instrumentation

Added in 7.2.0
val instrumentationInstrumentation

Access to the variant's instrumentation options.

javaCompilation

Added in 7.1.0
val javaCompilationJavaCompilation

Access to the variant's java compilation options.

lifecycleTasks

Added in 8.3.2
val lifecycleTasksLifecycleTasks

Provides access to the LifecycleTasks created for this component.

namespace

Added in 8.1.0
val namespaceProvider<String>

The namespace of the generated R and BuildConfig classes. Also, the namespace used to resolve any relative class names that are declared in the AndroidManifest.xml.

runtimeConfiguration

Added in 7.3.0
val runtimeConfigurationConfiguration

Access to the variant's runtime Configuration; for example, the debugRuntimeClasspath Configuration for the debug variant.

The returned Configuration should not be resolved until execution time.

sources

Added in 7.2.0
val sourcesSources

Access to variant's source files.