Artifacts

Added in 4.2.0

interface Artifacts


Access to the artifacts on a Variant object.

Artifacts are temporary or final files or directories that are produced by the Android Gradle plugin during the build. Depending on its configuration, each com.android.build.api.variant.VariantBuilder produces different versions of some of the output artifacts.

An example of temporary artifacts are .class files obtained from compiling source files that will eventually get transformed further into dex files. Final artifacts are APKs and bundle files that are not transformed further.

Artifacts are uniquely defined by their Artifact type and public artifact types that can be accessed from third-party plugins or build script are defined in SingleArtifact

Summary

Public functions

Unit
<FileTypeT : FileSystemLocation> add(
    type: MultipleArtifact<FileTypeT>,
    artifact: FileTypeT
)

This function is deprecated. Use addStaticDirectory instead

Unit
<MultipleArtifactT : MultipleArtifact<Directory> & Artifact.Appendable> addStaticDirectory(
    type: MultipleArtifactT,
    inputLocation: Directory
)

Add existing directory of type MultipleArtifactT to be combined with project artifact.

ScopedArtifacts

Some artifacts do not have a single origin (like compiled from source code).

Provider<FileTypeT>
<FileTypeT : FileSystemLocation> get(type: SingleArtifact<FileTypeT>)

Get the Provider of FileTypeT for the passed Artifact.

Provider<List<FileTypeT>>
<FileTypeT : FileSystemLocation> getAll(type: MultipleArtifact<FileTypeT>)

Get all the Providers of FileTypeT for the passed Artifact.

BuiltArtifactsLoader

Provides an implementation of BuiltArtifactsLoader that can be used to load built artifacts metadata.

TaskBasedOperation<TaskT>
<TaskT : Task> use(taskProvider: TaskProvider<TaskT>)

Access Task based operations.

Public functions

add

Added in 8.0.2
Deprecated in 8.4.0
fun <FileTypeT : FileSystemLocation> add(
    type: MultipleArtifact<FileTypeT>,
    artifact: FileTypeT
): Unit

Add an existing FileTypeT for the passed Artifact. For task generated folder or file, do not use this API but instead use the use API.

Parameters
type: MultipleArtifact<FileTypeT>

Type of the multiple artifact.

artifact: FileTypeT

is an existing static FileTypeT

addStaticDirectory

Added in 8.4.0
fun <MultipleArtifactT : MultipleArtifact<Directory> & Artifact.Appendable> addStaticDirectory(
    type: MultipleArtifactT,
    inputLocation: Directory
): Unit

Add existing directory of type MultipleArtifactT to be combined with project artifact. Do not use this for generated files, use the use API instead.

Parameters
type: MultipleArtifactT

type of the multiple artifact.

inputLocation: Directory

is an existing static file

forScope

Added in 7.4.1
fun forScope(scope: ScopedArtifacts.Scope): ScopedArtifacts

Some artifacts do not have a single origin (like compiled from source code). Some artifacts can be obtained from a combination of Tasks running or incoming dependencies. For example, classes used for dexing can come from compilation related tasks as well as .aar or .jar files expressed as a project dependency.

Therefore, these artifacts values can have a scope like ScopedArtifacts.Scope.PROJECT for values directly produced by this module (as a Task output most likely). Alternatively, the ScopedArtifacts.Scope.ALL adds all incoming dependencies (including transitive ones) to the previous scope.

For such cases, the artifact is represented as ScopedArtifact and can be manipulated by its own set of API that are scope aware.

Return ScopedArtifacts for a ScopedArtifacts.Scope

get

Added in 7.0.0
fun <FileTypeT : FileSystemLocation> get(type: SingleArtifact<FileTypeT>): Provider<FileTypeT>

Get the Provider of FileTypeT for the passed Artifact.

Parameters
type: SingleArtifact<FileTypeT>

Type of the single artifact.

getAll

Added in 7.0.0
fun <FileTypeT : FileSystemLocation> getAll(type: MultipleArtifact<FileTypeT>): Provider<List<FileTypeT>>

Get all the Providers of FileTypeT for the passed Artifact.

Parameters
type: MultipleArtifact<FileTypeT>

Type of the multiple artifact.

getBuiltArtifactsLoader

Added in 4.2.0
fun getBuiltArtifactsLoader(): BuiltArtifactsLoader

Provides an implementation of BuiltArtifactsLoader that can be used to load built artifacts metadata.

Returns
BuiltArtifactsLoader

A thread safe implementation of BuiltArtifactsLoader that can be reused.

use

Added in 4.2.0
fun <TaskT : Task> use(taskProvider: TaskProvider<TaskT>): TaskBasedOperation<TaskT>

Access Task based operations.

Parameters
taskProvider: TaskProvider<TaskT>

The TaskProvider for the TaskT that will be producing and/or consuming artifact types.

Returns
TaskBasedOperation<TaskT>

A TaskBasedOperation object using the passed TaskProvider for all its operations.