Aapt2

Added in 8.10.0-alpha08

@Incubating
interface Aapt2


Provides structured access to AAPT2 tool.

An instance of Aapt2 can be obtained via AndroidComponentsExtension.sdkComponents

For example, this is the structure of a org.gradle.api.Task that runs aapt2:

abstract class MyTaskUsingAapt2: DefaultTask() {
@get:Nested
abstract val aapt2Input: Property<com.android.build.api.variant.Aapt2>

@get:Inject
abstract val execOperations: ExecOperations

@TaskAction
fun execute() {
val aapt2Executable = aapt2Input.get().executable.get().asFile

// execute aapt2 help
execOperations.exec { spec ->
spec.commandLine(aapt2Executable)
spec.args("-h")
spec.isIgnoreExitValue = true // -h returns exit value 1
}
}
}

tasks.register<MyTaskUsingAapt2>("myTaskUsingAapt2") {
// get an instance of Aapt2
this.aapt2Input.set(androidComponents.sdkComponents.aapt2)
}

Summary

Public properties

Provider<RegularFile>

Path to the AAPT2 executable file from the Android SDK

Provider<String>

Version of build tools.

Public properties

executable

Added in 8.10.0-alpha08
val executableProvider<RegularFile>

Path to the AAPT2 executable file from the Android SDK

version

Added in 8.10.0-alpha08
val versionProvider<String>

Version of build tools. It is used as an input to allow correct build cache behaviour across different platforms