# Optimization

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


```
interface Optimization
```

<br />

*** ** * ** ***

DSL object for configurations aimed for optimizing build process(e.g. speed, correctness). This DSL object is applicable to buildTypes and productFlavors.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `@https://docs.gradle.org/current/javadoc/org/gradle/api/Incubating.html [baselineProfile](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/Optimization#baselineProfile(kotlin.Function1))(action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/BaselineProfile.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` **This function is deprecated.** Use buildType.baselineProfile{} |
| `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/dsl/Optimization#keepRules(kotlin.Function1)(action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/KeepRules.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` Configure keep rules inherited from external library dependencies |

| ### Public properties |
|---|---|
| `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/dsl/Optimization#enable()` Specifies whether to enable code shrinking and resource optimization. |
| `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/dsl/Optimization#packageScope()` Specifies what packages are included for optimization. |

## Public functions

### baselineProfile

Added in 8.2.0 Deprecated in 9.6.0-alpha03

```
@Incubating
fun [baselineProfile](https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/Optimization#baselineProfile(kotlin.Function1))(action: BaselineProfile.() -> Unit): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> Use buildType.baselineProfile{}

Configure baseline profile properties

### keepRules

Added in 7.3.0

```
fun keepRules(action: KeepRules.() -> Unit): Unit
```

Configure keep rules inherited from external library dependencies

## Public properties

### enable

Added in 8.13.0

```
var enable: Boolean
```

Specifies whether to enable code shrinking and resource optimization. Property works for applications only. For other types it will be ignored

By default, value is false to avoid runtime issue. When enabled the Android plugin uses R8 for optimization.

Flavours merge this property with "or" rule. That means having this enable=true sticks.

### packageScope

Added in 8.13.0

```
val packageScope: SetProperty<String>
```

Specifies what packages are included for optimization. Those may be local code packages and external libraries packages. You can include

- classes for a single package, like "com.example.app.\*"

- classes from package and all subpackages, like "androidx.\*\*"

- everything "\*\*"

Default (convention) value is "\*\*"