# Component

[View Source](https://cs.android.com/search?q=file:com/android/build/api/variant/Component.kt+class:com.android.build.api.variant.Component) Added in 7.0.0


```
interface Component : ComponentIdentity
```

<br />

Known direct subclasses [TestComponent](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestComponent), [TestFixtures](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestFixtures), [Variant](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant)

|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestComponent` | Model for test components that contains build-time properties. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestFixtures` | Model for Test Fixtures components that contains build-time properties |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant` | Model for variant components that only contains build-time properties |

Known indirect subclasses [AndroidTest](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidTest), [ApplicationVariant](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ApplicationVariant), [DeviceTest](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTest), [DynamicFeatureVariant](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DynamicFeatureVariant), [HostTest](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest), [KotlinMultiplatformAndroidVariant](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/KotlinMultiplatformAndroidVariant), [LibraryVariant](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/LibraryVariant), [TestVariant](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestVariant), [UnitTest](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/component/UnitTest), [UnitTest](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/UnitTest)

|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidTest` | Model for Android Test components that contains build-time properties |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ApplicationVariant` | Model for application components that only contains build-time properties. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DeviceTest` | Model for Device Test components that contains build-time properties |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/DynamicFeatureVariant` | Model for dynamic feature components that only contains build-time properties. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/HostTest` | Model for Host Test components that contains build-time properties. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/KotlinMultiplatformAndroidVariant` | Properties for the main Variant of a kotlin multiplatform android library |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/LibraryVariant` | Model for library components that only contains build-time properties. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestVariant` | Model for test components that only contains build-time properties. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/component/UnitTest` | **This interface is deprecated.** Use the com.android.build.api.variant package |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/UnitTest` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component` for unit tests |

*** ** * ** ***

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 `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant` which are production build output (APKs, AARs), and `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestComponent` that are test components. `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/TestFixtures` is another separate component. See these types for more information.

See `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/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 `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html` linking.

For example:

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

Because links between `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html` 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 `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html#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 `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentBuilder`. These will contain the final values set after all `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidComponentsExtension#beforeVariants(com.android.build.api.variant.VariantSelector,kotlin.Function1)` callbacks have been executed. It is safe to read these values during configuration time.

See [here](https://developer.android.com/build/extend-agp#variant-api-artifacts-tasks) for more information

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#computeTaskName(kotlin.String,kotlin.String)(action: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, subject: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Utility method to create unique task name for component. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#configureJavaCompileTask(kotlin.Function1)(action: (https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/JavaCompile.html) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Runs an action to configure Components's java compilation `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/JavaCompile.html` task. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` | `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#getResolvableConfiguration(kotlin.String)(sourceSetConfigurationsAffix: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` Access to the component's resolvable configuration corresponding to the source set configurations added via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidComponentsExtension#addSourceSetConfigurations(kotlin.String)`. |

| ### Public properties |
|---|---|
| `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#annotationProcessorConfiguration()` Access to the variant's annotation processor `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugAnnotationProcessor `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/artifact/Artifacts` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#artifacts()` Access to the variant's buildable artifacts for build customization. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileCollection.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#compileClasspath()` Access to the variant's compile classpath. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#compileConfiguration()` Access to the variant's compile `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugCompileClasspath `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#debuggable()` Whether the produced artifacts will be debuggable |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Instrumentation` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#instrumentation()` Access to the variant's instrumentation options. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/JavaCompilation?` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#javaCompilation()` Access to the variant's java compilation options. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/LifecycleTasks` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#lifecycleTasks()` Provides access to the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/LifecycleTasks` created for this component. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#namespace()` The namespace of the generated R and BuildConfig classes. |
| `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#runtimeConfiguration()` Access to the variant's runtime `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugRuntimeClasspath `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Sources` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Component#sources()` Access to variant's source files. |

### Inherited properties

From [com.android.build.api.variant.ComponentIdentity](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity) `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#buildType()`

Build type name.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html?` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#flavorName()`

The multi-flavor name of the variant.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#name()`

Component's name.
`https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-pair/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html>>` `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/ComponentIdentity#productFlavors()`

List of flavor names.

## Public functions

### computeTaskName

Added in 8.4.0

```
@Incubating
fun computeTaskName(action: String, subject: String): String
```

Utility method to create unique task name for component. You still need to assign task name during task registration. For variant `getTaskName("produce", "manifestReport")` will return produceDebugManifestReport

### configureJavaCompileTask

Added in 9.6.0-alpha03

```
@Incubating
fun configureJavaCompileTask(action: (JavaCompile) -> Unit): Unit
```

Runs an action to configure Components's java compilation `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/JavaCompile.html` task.

The action will only run if the task is configured.

Where possible, use the AGP DSL and API

Note: This API is here to allow access to the java compiler elements that aren't exposed explicitly in the AGP DSL or API, such as `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileOptions#targetCompatibility(kotlin.Any)` for example. Properties set using this API don't propagate anywhere else. For example if you set `compileTask.targetCompatibility`, it will not update `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileOptions#targetCompatibility(kotlin.Any)`

Example :

```
androidComponents {
    onVariants { variant ->
        variant.configureJavaCompileTask { compileTask ->
            compileTask.options.compilerArgs.add("-Werror")
        }
    }
}
```

| Parameters |
|---|---|
| `action: (https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/JavaCompile.html) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | to configure the `https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/compile/JavaCompile.html` task. |

### getResolvableConfiguration

Added in 8.9.0

```
@Incubating
fun getResolvableConfiguration(sourceSetConfigurationsAffix: String): Configuration
```

Access to the component's resolvable configuration corresponding to the source set configurations added via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidComponentsExtension#addSourceSetConfigurations(kotlin.String)`.

Example usage:

```
androidComponents {
    addSourceSetConfigurations("foo")
    onVariants { variant ->
        val resolvableConfiguration = variant.getResolvableConfiguration("foo")
        variant.nestedComponents.forEach { component ->
            val nestedResolvableConfiguration =
                component.getResolvableConfiguration("foo")
        }
    }
}
```

The returned `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` should not be resolved until execution time.

## Public properties

### annotationProcessorConfiguration

Added in 7.3.0

```
val annotationProcessorConfiguration: Configuration
```

Access to the variant's annotation processor `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugAnnotationProcessor `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant.

The returned `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` should not be resolved until execution time.

### artifacts

Added in 7.0.0

```
val artifacts: Artifacts
```

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

### compileClasspath

Added in 7.3.0

```
val compileClasspath: FileCollection
```

Access to the variant's compile classpath.

The returned `https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileCollection.html` should not be resolved until execution time.

### compileConfiguration

Added in 7.3.0

```
val compileConfiguration: Configuration
```

Access to the variant's compile `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugCompileClasspath `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant.

The returned `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` should not be resolved until execution time.

### debuggable

Added in 8.3.1

```
val debuggable: Boolean
```

Whether the produced artifacts will be debuggable

### instrumentation

Added in 7.2.0

```
val instrumentation: Instrumentation
```

Access to the variant's instrumentation options.

### javaCompilation

Added in 7.1.0

```
val javaCompilation: JavaCompilation?
```

Access to the variant's java compilation options.

### lifecycleTasks

Added in 8.3.1

```
val lifecycleTasks: LifecycleTasks
```

Provides access to the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/LifecycleTasks` created for this component.

### namespace

Added in 8.1.0

```
val namespace: Provider<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 runtimeConfiguration: Configuration
```

Access to the variant's runtime `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html`; for example, the debugRuntimeClasspath `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` for the debug variant.

The returned `https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html` should not be resolved until execution time.

### sources

Added in 7.2.0

```
val sources: Sources
```

Access to variant's source files.