Android Gradle Plugin 8.1.0 (July 2023)

Android Gradle plugin 8.1.0 is a major release that includes a variety of new features and improvements.

Compatibility

Minimum version Default version Notes
Gradle 8.0 8.0 To learn more, see updating Gradle.
SDK Build Tools 33.0.1 33.0.1 Install or configure SDK Build Tools.
NDK N/A 25.1.8937393 Install or configure a different version of the NDK.
JDK 17 17 To learn more, see setting the JDK version.

Kotlin DSL is the default for build configuration

New projects now use the Kotlin DSL (build.gradle.kts) by default for build configuration. This offers a better editing experience than the Groovy DSL (build.gradle) with syntax highlighting, code completion, and navigation to declarations. Note that if you're using AGP 8.1 and the Kotlin DSL for build configuration, you should use Gradle 8.1 for the best experience. To learn more, see the Kotlin DSL migration guide.

Automatic per-app language support

Starting with Android Studio Giraffe Canary 7 and AGP 8.1.0-alpha07, you can configure your app to support per-app language preferences automatically. Based on your project resources, the Android Gradle plugin generates the LocaleConfig file and adds a reference to it in the final manifest file, so you no longer have to do it manually. AGP uses the resources in the res folders of your app modules and any library module dependencies to determine the locales to include in the LocaleConfig file.

Note that the automatic per-app language feature supports apps that run Android 13 (API level 33) or higher. To use the feature, you must set compileSdkVersion to 33 or higher. To configure per-app language preferences for prior versions of Android, you still need to use the APIs and in-app language pickers.

To enable automatic per-app language support, specify a default locale:

  1. In the app module's res folder, create a new file called resources.properties.
  2. In the resources.properties file, set the default locale with the unqualifiedResLocale label. To form the locale names, combine the language code with the optional script and region codes, separating each with a dash:

    For example if your default locale is American English:

        unqualifiedResLocale=en-US
        

AGP adds this default locale and any alternative locales you've specified, using values-* directories in the res folder, to the auto-generated LocaleConfig file.

Automatic per-app language support is off by default. To turn the feature on, use the generateLocaleConfig setting in the androidResources {} block of the module-level build.gradle.kts file (build.gradle file if you're using Groovy):

Kotlin

android {
  androidResources {
    generateLocaleConfig = true
  }
}

Groovy

android {
  androidResources {
    generateLocaleConfig true
  }
}

Android Lint contains bytecode targeting JVM 17

Starting with AGP 8.1.0-alpha04, Android Lint contains bytecode targeting JVM 17. If you write custom lint checks, you need to compile with JDK 17 or higher and specify jvmTarget = '17' in your Kotlin compiler options.

To learn more about the lint tool, see Improve your code with lint checks.

Native library compression setting moved to DSL

Starting with AGP 8.1.0-alpha10, you'll get a warning if you don't configure native library compression using the DSL instead of the manifest. The following guidance explains how to update your configuration to use the DSL. To get help making these updates, use the AGP Upgrade Assistant (Tools > AGP Upgrade Assistant).

To use uncompressed native libraries, remove the android::extractNativeLibs attribute from the manifest and add the following code to the module-level build.gradle.kts file (build.gradle file if you're using Groovy):

Kotlin

android {
  packagingOptions {
    jniLibs {
      useLegacyPackaging = false
    }
  }
}

Groovy

android {
  packagingOptions {
    jniLibs {
      useLegacyPackaging false
    }
  }
}

Experimental build flags

These are experimental flags for configuring your build available in AGP 8.1.

Flag Added in Default value Notes
android.experimental.useDefaultDebugSigningConfigForProfileableBuildtypes AGP 8.0 false Enabling this with no signing configs specified causes AGP to use the default debug signing config when running a profileable or debuggable build. This flag is disabled by default to encourage build authors to declare specific profiling signing configs.
android.experimental.library.desugarAndroidTest AGP 8.0 false This flag lets library builders enable core library desugaring for test APKs without affecting the AAR produced, for example through linting. We plan to eventually support this behavior in the Variant API.
android.experimental.testOptions.managedDevices.customDevice AGP 8.0 false If enabled, Gradle Managed Devices allows a user-defined custom device type that can be provided by a plugin. This flag must be enabled if you want to use the Firebase Test Lab plugin.
android.lint.printStackTrace AGP 8.0 false If enabled, Android lint prints a stacktrace if it crashes. This flag has the same capabilities as the LINT_PRINT_STACKTRACE environment variable.
android.experimental.testOptions.managedDevices.maxConcurrentDevices AGP 8.0 None Specifies the maximum number of concurrent Gradle Managed Devices (AVDs) to be active at any one point in time. If the value is 0 or negative, there is no maximum number of devices.
android.experimental.testOptions.installApkTimeout AGP 8.0 None The timeout duration in seconds to install an APK. If the value is 0 or negative, it will be set to a default value by UTP.