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.

Fixed issues

Android Gradle plugin 8.1.0

Fixed Issues
Android Gradle Plugin
`com.android.build.gradle.tasks.ShaderCompile` issues with configuration cache
Adding to Java resources using AGP APIs breaks configuration cache
[Android Studio : Flamingo | 2022.2.1 Canary 8] liblog.so is packaged inside the APK
KGP reads manifest during configuration, invalidating configuration cache on manifest change
Build warning message unclear when problem in merged manifest
Upgrading to AGP 7.4 results in a StackOverflowError
ClassNotFoundException in dynamic feature that depends directly on Kotlin library subproject
processDebugUnitTestManifest is failing with manifest placeholders for test variants
processDebugUnitTestManifest is failing with manifest placeholders for test variants
namespace property probably belongs to HasAndroidResources
Can't disable "Gradle files have changed since last project sync" message
"We recommend using a newer Android Gradle plugin" when there isn't a newer one
processDebugUnitTestManifest is failing with manifest placeholders for test variants
Boolean flag for disabling compile SDK check in CheckAarMetadataTask
Build error refers to API level 34, which does not exist
Setting JVM toolchain does not affect JavaCompile targetCompatibility value
Navigation deepLink entries with wildcard domains don't have an `android:host` attribute in merged manifest
processDebugMainManifest task is failed since Android Gradle Plugin 8.1
Can we remove AnalyticsRecordingTask?
Content of output-metadata.json is not consistent
Can we remove AnalyticsRecordingTask?
Content of output-metadata.json is not consistent
Setting JVM toolchain does not affect JavaCompile targetCompatibility value
Navigation deepLink entries with wildcard domains don't have an `android:host` attribute in merged manifest
processDebugMainManifest task is failed since Android Gradle Plugin 8.1
Android Studio doesn't respect the STUDIO_GRADLE_JDK environment variable
Custom source types should create multi-flavor sourcesets
DependenciesInfoBuilder needs API update + doc
DexingNoClasspathTransform (minSdk >= 24) with Java 11 target fails due to missing nest members
DslExtension.Builder.extendProjectWith() not working as described in Groovy
Add VariantSelector.withFlavor API that doesn't use kotlin.Pair
AndroidLintAnalysisTask (:lintAnalyzeExternalRelease) has a cache miss because `proguard.txt` has changed
App merged manifest contains extractNativeLibs and useEmbeddedDex attributes from dependencies
AGP: Expose path to AIDL tool and framework AIDL file as public API
Request: let the IDE offer a fix for "PermittedSubclasses requires ASM9"
Bug: "Enable KSP and use the KSP processor for this dependency instead" just goes to a website
Gradle 8.1 breaks configuration caching due to .gradle/.android/analytics.settings
generateLocaleConfig in agp 8.1.0 uses non-deterministic ordering, breaking reproducible builds
Dexer (D8)
Core library desugaring crashing app after recent updates.
agp 8.1.0 regression with API 21 - F/dex2oat ( 4176): art/compiler/driver/compiler_driver.cc:1181] Check failed: !method->IsAbstract()
Lint
Lint only checks safe casts for directly implemented interfaces, not inherited ones
Lint doesn't check valid casts for call receivers
TypedArray#close (API 31) not desugared but AS does not display warning when used in try-with-resources
Bug: false positive warning of "The 'BC' provider is deprecated and as of Android P..."
Lint false positive about remember after Kotlin upgrade to 1.8.0
False positive Lint warning for SDK_INT checks performed inside a method with a enum parameter
TypographyQuotes lint check does not work on escaped quotes
TrustAllX509TrustManager lint check incorrectly flags interfaces that extends X509TrustManager
Reformatting just the inserted code of a replace fix
Lint: intention preview throws exception for ReplaceStringQuickFix
Shrinker (R8)
VerifyError: Verifier rejected class when using R8 with Kotlin 1.8.20
R8 on AGP 8 breaks Google Fit service
Including source file information with residual names that overlap input names is not correctly represented
R8 fails during Compose build with ArrayIndexOutOfBoundsException
Simple StringBuilder related code misses tail call to append in release or debuggable=false mode
A corner case in VirtualDispatchMethodArgumentPropagator.shouldActivateMethodStateGuardedByBounds() method
dex-startup-optimization results in java.lang.VerifyError: Rejecting class
Crash with Verification error on Android 12+

Android Gradle plugin 8.1.1

Fixed Issues
Dexer (D8)
Java 16 Records: equals(null) throws NullPointerException
Shrinker (R8)
java.lang.VerifyError: Verifier rejected class
Build gets stuck on :minifyReleaseWithR8 when using Apache POI library
Rejecting invocation when enable r8 optimize
NoClassDefFoundError for java.lang.reflect.Executable

Android Gradle plugin 8.1.2

Fixed Issues
Android Gradle Plugin
androidResources is not available in the android library module
[AGP 8.1.0] ./gradlew test fails with "Unable to find manifest output" if both splits.abi.isEnable and testOptions.unitTests.isIncludeAndroidResources are true
Shrinker (R8)
Kotlin 1.9 causes Kotlin lambdas to be destroyed by R8 if nullchecks are stripped
R8 fails with "Undefined value encountered during compilation" for play-services-measurement-21.3.0-runtime.jar

Android Gradle plugin 8.1.3

Fixed Issues
Android Gradle Plugin
[AGP 8.1.0] ./gradlew test fails with "Unable to find manifest output" if both splits.abi.isEnable and testOptions.unitTests.isIncludeAndroidResources are true
Build failure after updating to AGP 8.1

Android Gradle plugin 8.1.4

Fixed Issues
Android Gradle Plugin
Do not run dexing task on subprojects' classes when they are already dex'd through artifact transforms