# Instrumentation

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


```
interface Instrumentation
```

<br />

*** ** * ** ***

Options to register asm class visitors and to configure the instrumentation process.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Instrumentation#setAsmFramesComputationMode(com.android.build.api.instrumentation.FramesComputationMode)(mode: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/FramesComputationMode)` Sets the frame computation mode that will be applied to the bytecode of the classes instrumented by ASM visitors registered through `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Instrumentation#transformClassesWith(java.lang.Class,com.android.build.api.instrumentation.InstrumentationScope,kotlin.Function1)`. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `<ParamT : https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/InstrumentationParameters> https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Instrumentation#transformClassesWith(java.lang.Class,com.android.build.api.instrumentation.InstrumentationScope,kotlin.Function1)( classVisitorFactoryImplClass: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html<https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory<ParamT>>, scope: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/InstrumentationScope, instrumentationParamsConfig: (ParamT) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html )` Registers an asm class visitor to instrument the classes defined by the given scope. |

| ### Public properties |
|---|---|
| `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/SetProperty.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/Instrumentation#excludes()` The set of glob patterns to exclude from instrumentation. |

## Public functions

### setAsmFramesComputationMode

Added in 7.2.0

```
fun setAsmFramesComputationMode(mode: FramesComputationMode): Unit
```

Sets the frame computation mode that will be applied to the bytecode of the classes instrumented by ASM visitors registered through `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Instrumentation#transformClassesWith(java.lang.Class,com.android.build.api.instrumentation.InstrumentationScope,kotlin.Function1)`. The default mode is to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/FramesComputationMode#COPY_FRAMES`.

When setting this multiple times, the mode with the highest enum value will be selected.

### transformClassesWith

Added in 7.2.0

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

Registers an asm class visitor to instrument the classes defined by the given scope. An instance of the factory will be instantiated and used to create visitors for each class.

Example:

```
androidComponents {
    onVariants(selector().all(), {
        instrumentation.transformClassesWith(AsmClassVisitorFactoryImpl.class,
                                             InstrumentationScope.Project) { params ->
            params.x = "value"
        }
        instrumentation.setAsmFramesComputationMode(COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS)
    })
}
```

| Parameters |
|---|---|
| `classVisitorFactoryImplClass: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html<https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory<ParamT>>` | the factory class implementing `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory` |
| `scope: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/InstrumentationScope` | either instrumenting the classes of the current project or the project and its dependencies |
| `instrumentationParamsConfig: (ParamT) -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | the configuration function to be applied to the instantiated `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/InstrumentationParameters` object before passed to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory#createClassVisitor(com.android.build.api.instrumentation.ClassContext,org.objectweb.asm.ClassVisitor)`. |

## Public properties

### excludes

Added in 7.2.0

```
val excludes: SetProperty<String>
```

The set of glob patterns to exclude from instrumentation. Classes matching any of these patterns in the project sources and dependencies jars do not get instrumented by any `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/instrumentation/AsmClassVisitorFactory` registered via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Instrumentation#transformClassesWith(java.lang.Class,com.android.build.api.instrumentation.InstrumentationScope,kotlin.Function1)`.

Do not add the file extension to the end as the filtration is done on compiled classes and the `.class` suffix is not included in the pattern matching.

Example usage:

```
androidComponents {
    onVariants(selector().all(), {
        instrumentation.excludes.add("com`/`example`/`donotinstrument`/`**")
        instrumentation.excludes.add("**`/`*Test")
    })
}
```