# Aapt2

# Aapt2

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

<br />

```
interface Aapt2
```

<br />

*** ** * ** ***

Provides structured access to AAPT2 tool.

An instance of[Aapt2](https://developer.android.com/reference/tools/gradle-api/9.0/com/android/build/api/variant/Aapt2)can be obtained via[AndroidComponentsExtension.sdkComponents](https://developer.android.com/reference/tools/gradle-api/9.0/com/android/build/api/variant/AndroidComponentsExtension#sdkComponents())

For example, this is the structure of a[org.gradle.api.Task](https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html)that runs aapt2:  

```scalate-server-page
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](https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html)`<`[RegularFile](https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFile.html)`>` | [executable](https://developer.android.com/reference/tools/gradle-api/9.0/com/android/build/api/variant/Aapt2#executable()) Path to the[AAPT2](https://developer.android.com/tools/aapt2)executable file from the Android SDK |
| [Provider](https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html)`<`[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>`            | [version](https://developer.android.com/reference/tools/gradle-api/9.0/com/android/build/api/variant/Aapt2#version()) Version of build tools.                                                                                 |

## Public properties

### executable

Added in 8.10.1  

```
val executable: Provider<RegularFile>
```

Path to the[AAPT2](https://developer.android.com/tools/aapt2)executable file from the Android SDK  

### version

Added in 8.10.1  

```
val version: Provider<String>
```

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