Android Gradle Plugin 8.0.0 (April 2023)

Android Gradle plugin 8.0.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 30.0.3 30.0.3 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.

Patch releases

The following is a list of the patch releases for Android Gradle Plugin 8.0.

Android Gradle Plugin 8.0.2 (May 2023)

For a list of bugs fixed in AGP 8.0.2, see the Android Studio 2022.2.1 closed issues.

Android Gradle Plugin 8.0.1 (May 2023)

This minor update includes the following bug fixes:

Fixed issues
Error: "No VersionRequirement with the given id in the table" after upgrading AGP 7.2.2 -> 7.4.0
R8 NullPointerException at markTypeAsLive AGP 7.4.1
[R8 4.0.53] Hard class verification failure on Android 11

Breaking change: namespace required in module-level build script

You must set the namespace in the module-level build.gradle.kts file, rather than the manifest file. You can start using the namespace DSL property starting with AGP 7.3. To learn more, see Set a namespace.

When migrating to the namespace DSL, be aware of the following issues:

  • Previous versions of AGP infer the test namespace from the main namespace, or application ID, incorrectly in some cases. The AGP Upgrade Assistant blocks the upgrade if it finds that your project's main namespace and test namespace are the same. If the upgrade is blocked, you need to manually change testNamespace and modify your source code accordingly.
  • After you change the test namespace, it's possible that your code compiles but your instrumented tests fail at runtime. This can happen if your instrumented test source code references a resource defined in both your androidTest and app sources.

For more information, see issue #191813691 comment #19.

Breaking changes: build option default values

Starting with AGP 8.0, the default values for these flags have changed to improve build performance. To get help adjusting your code to support some of these changes, use the AGP Upgrade Assistant (Tools > AGP Upgrade Assistant). The Upgrade Assistant guides you through updating your code to accommodate the new behavior or setting flags to preserve the previous behavior.

Flag New default value Previous default value Notes
android.defaults.buildfeatures.buildconfig false true AGP 8.0 doesn't generate BuildConfig by default. You need to specify this option using the DSL in the projects where you need it.
android.defaults.buildfeatures.aidl false true AGP 8.0 doesn't enable AIDL support by default. You need to specify this option using the DSL in the projects where you need it. This flag is planned to be removed in AGP 9.0.
android.defaults.buildfeatures.renderscript false true AGP 8.0 doesn't enable RenderScript support by default. You need to specify this option using the DSL in the projects where you need it. This flag is planned to be removed in AGP 9.0.
android.nonFinalResIds true false AGP 8.0 generates R classes with non-final fields by default.
android.nonTransitiveRClass true false AGP 8.0 generates R classes for resources defined in the current module only.
android.enableR8.fullMode true false AGP 8.0 enables R8 full mode by default. For more details, see R8 full mode.

Breaking changes: enforced build option values

Starting with AGP 8.0, you can no longer change the values for these flags. If you specify them in the gradle.properties file, the value is ignored and AGP prints warnings.

Flag Enforced value Notes
android.dependencyResolutionAtConfigurationTime.warn true AGP 8.0 emits a warning if it detects configuration resolution during the configuration phase because it negatively impacts Gradle configuration times.
android.r8.failOnMissingClasses true AGP 8.0 fails builds that use R8 if there are missing classes to ensure better DEX optimization. To address this, you need to add the missing libraries or -dontwarn keep rules. For more details, see Missing class warnings in R8 shrinker.
android.testConfig.useRelativePath true When support for using Android resources, assets, and manifests in unit tests is enabled, AGP 8.0 generates a test_config.properties file that contains only relative paths. This ensures that Android unit tests can always use the Gradle build cache.
android.useNewJarCreator true AGP uses the Zipflinger library when creating JAR files to improve build performance.
android.bundletool.includeRepositoriesInDependencyReport true When adding SDK dependency information in AABs and APKs is enabled, AGP 8.0 also adds a list of project repositories to this information. To learn more, see Dependency information for Play Console.
android.enableArtProfiles true Baseline profiles are now always generated. See Baseline Profiles for details.
android.enableNewResourceShrinker true Use the new resource shinker implementation by default. The new resource shrinker includes support for dynamic features.
android.enableSourceSetPathsMap true Used for computing relative resource path mappings, so Gradle builds are up-to-date more often.
android.cacheCompileLibResources true Compiled library resources can now be cached by default because Gradle tracks resources files relative to the project location. Requires android.enableSourceSetPathsMap to be enabled.
android.disableAutomaticComponentCreation true AGP 8.0 creates no SoftwareComponent by default. Instead AGP creates SoftwareComponents only for variants that are configured to be published using the publishing DSL.

New stable flag for execution profile

AGP includes the new flag android.settings.executionProfile. Use this flag to override the default execution profile from the SettingsExtension. To learn more, see the settings plugin documentation.

To preview experimental flags, see the preview release notes.

Kotlin lazy property assignment not supported

If you're using Gradle's Kotlin DSL for your build scripts, note that Android Studio and AGP 8.0 don't support the experimental property assignment using the = operator. For more information about this feature, see the release notes and documentation.

Build Analyzer task categories

Starting with Android Studio Flamingo, Build Analyzer has a new default view for tasks that impact build duration. If your project uses AGP 8.0 or higher, instead of displaying tasks individually, Build Analyzer groups them by category. For example, tasks specific to Android Resources, Kotlin, or Dexing are grouped together and then sorted by build duration. This makes it easy to know what category has the most impact on build time. Expanding each category displays a list of the corresponding tasks. To display tasks individually, without grouping, use the Group by drop-down.

Build Analyzer task categories.

New settings plugin

AGP 8.0.0-alpha09 introduces the new settings plugin. The settings plugin lets you centralize global configurations—configurations that apply to all modules—in one place so you don't need to copy and paste the configurations in multiple modules. In addition, you can use the settings plugin to create tool execution profiles, or different instructions for how to run a tool, and switch among them.

To use the settings plugin, apply the plugin in the settings.gradle file:

apply plugin 'com.android.settings'

Centralize global configurations

To configure global configurations, use the new android block in the settings.gradle file. Here's an example:

android {
  compileSdk 31
  minSdk 28
  ...
}

Tool execution profiles

The settings plugin also lets you create execution profiles for some tools. An execution profile determines how a tool is run; you can select different execution profiles depending on the environment. In an execution profile, you can set JVM arguments for a tool and configure it to run in a separate process. Currently, only the R8 tool is supported.

Create execution profiles and set the default execution profile in the settings.gradle file, as shown in the following example:

android {
  execution {
    profiles {
      high {
        r8 {
          jvmOptions += ["-Xms2048m", "-Xmx8192m", "-XX:+HeapDumpOnOutOfMemoryError"]
          runInSeparateProcess true
        }
      }
      low {
        r8 {
          jvmOptions += ["-Xms256m", "-Xmx2048m", "-XX:+HeapDumpOnOutOfMemoryError"]
          runInSeparateProcess true
        }
      }
      ci {
        r8.runInSeparateProcess false
      }
    }
    defaultProfile "low"
  }
}

To override the default profile, select a different profile using the android.experimental.settings.executionProfile property in the gradle.properties file:

android.experimental.settings.executionProfile=high

You can also set this property using the command line, which lets you set up different workflows. For example if you have a continuous integration workflow you can use the command line to change the execution profile without having to change the settings.gradle file:

./gradlew assembleRelease \
  -Pandroid.experimental.settings.executionProfile=ci

JDK 17 required to run AGP 8.0

When using Android Gradle Plugin 8.0 to build your app, JDK 17 is now required to run Gradle. Android Studio Flamingo bundles JDK 17 and configures Gradle to use it by default, which means that most Android Studio users don't need to make any configuration changes to their projects.

If you need to manually set the JDK version used by AGP inside of Android Studio, you need to use JDK 17 or higher.

When using AGP independent of Android Studio, upgrade the JDK version by setting the JAVA_HOME environment variable or the -Dorg.gradle.java.home command-line option to your installation directory of JDK 17.

Fixed issues

Android Gradle plugin 8.0.0

Fixed Issues
Android Gradle Plugin
Flaky build failure in MergeResources task
JavaPluginConvention and HasConvention is deprecated
Wrong and inconsistent file location for new transform API
Android Gradle Plugin should not use the deprecated GUtil.toWords(string) function
Android Gradle Plugin should not use the deprecated ConfigureUtil.configure(closure, target) function
Update AGP tests to use KGP 1.7.20-Beta
Gradle 7.4 fails (could not create instance of AnalyticsService)
New "unknown enum constant" from javac on AGP 7.4.0-alpha09
MergeGeneratedProguardFilesCreationAction configuration is slow even with configuration caching on
[AGP] Add generated source directory to IDE model (Variant API)
JavaPluginConvention and HasConvention is deprecated
Don't add ignorewarnings to R8 by default
Warn when proguard files do not exist
AGP 7.3.0 breaks gradle sync for gradle platform projects
apksig library: ApkVerifier$Result.getV4SchemeSigners() is marked private
Stop creating androidJacocoAnt configuration if coverage is not enabled
Using @IntDef in a library component doesn't generate annotations.zip in the aar
Unable to find common super type for and
Add a gradle property version of LINT_PRINT_STACKTRACE=true
Stale prefab artifacts being packaged into AAR
Migrate from destination property to outputLocation property to address deprecation warning and prepare for Gradle 9.0
Take `--release` flag into account when setting up JavaCompile task
[AGP-7.3.0-beta03] ShrinkResourcesNewShrinkerTask is failed when there is an empty line after xml declaration
lintVital target run by default in a debug variant
Warn when proguard files do not exist
AGP tries to add kotlinOptions.freeCompilerArgs on task execution phase
Gradle sync failed: Sync failed: reason unknown
DependencyReportTask is incompatible with the configuration cache
Overriding resources with resValue in build.gradle leads to Error: Duplicate resources
'debug' build type has default signing key, others do not
Using dynamic features and resource shrinking cause runtime crash
'debug' build type has default signing key, others do not
generated source directory listed as Java directory in lint model's main source provider
Gradle 8.0-milestone-2 causes exception in AGP
Optimize manifest merging for apps and library
Add gradle-settings-api to the javadoc generation
New "unknown enum constant" from javac on AGP 7.4.0-alpha09
AGP 7.4.0-alpha09 generates builds that won't upload into Firebase App Distribution
lint.xml in modules is not considered for UP-TO-DATE check of lint tasks
Android Gradle Plugin 7.0+ and Android Tests issue: Cannot find resource: id
configureCMakeDebug flakily crashing with null pointer exception
IllegalAccessError upgrading project to AS2022.2.1.5, FireBasePerfPlugin
Sync fails with cryptic error "Collection contains no element matching the predicate."
Instrumentation API does not transform local file dependencies
`AnnotationProcessorOptions.arguments are queried` error when updating to 7.4 Beta 1
Move Gradle public plugins to gradle-api and remove BasePlugin.getExtension
r8.jvmArgs don't get used
JDK17 as min version required for AGP
AGP 8.0.0 A8 breaks baseline profiles
Change 'compileSdkVersion' to 'compileSdk' in CheckAarMetadataTask message in AGP 8.0
AGP 7.4.0-rc01 breaks Variant API with "Querying the mapped value of map(provider(java.util.Set)) before task '...' has completed is not supported"
`com.android.build.gradle.tasks.ShaderCompile` issues with configuration cache
Adding to Java resources using AGP APIs breaks configuration cache
Lint plugin is not part of gradle-api
DexingFileDependenciesTask.outputKeepRules is a directory but is marked as an OutputFile
Upgrading to AGP 7.4 results in a StackOverflowError
processDebugUnitTestManifest is failing with manifest placeholders for test variants
Lint accesses source sets information without dependencies
Build error refers to API level 34, which does not exist
"We recommend using a newer Android Gradle plugin" when there isn't a newer one
android.injected.testOnly=false does not work
Dexer (D8)
Dex merging error related to global synthetics after upgrading AS Canary 6 to 7
Update Kotlin metadata library to version 0.6.0
Workaround for JDK-8272564 seems to be required on API level 28-30
Lint
ResourceType lint check is not working for kotlin sources
VersionChecks doesn't handle Kotlin range checks
False positive for InlinedApi when wrapped
Lint false positive Recycle regarding openInputStream
[BuildTool/Lint] ChecksSdkIntAtLeast constructor property
Lint: PartialResults merging works incorrectly
Android Studio improperly marks specified version as out-of-date.
AndroidDeprecationInspection.DeprecationFilter EP is never registered in android-plugin.xml file
AccessibilityDetector lint check explanation is outdated
Lint SDK_INT checks should understand temporary local variables
Error when TestMode.TYPE_ALIAS replace Function type with typealias
Bug: when ObjectAnimator is created outside of current code block, there are false-positive warnings of not starting it #38
Lint: NPE due to querying Application instance in mergeOnly mode
NonConstantResourceId lint rule cannot detect to assign constant values from resource id
not showing error on view id
Failure to deserialize lint resources cache results in a lint error (but should be a warning)
AGP Flamingo Alpha 8 Lint NewApi Desugar Regression
TypedArray#close (API 31) not desugared but AS does not display warning when used in try-with-resources
Lint doesn't check valid casts for call receivers
Lint only checks safe casts for directly implemented interfaces, not inherited ones
Lint Integration
Baseline file is currently an Input and an Output of the Lint tasks
Shrinker (R8)
NPE / assertion error in CF frame verifier
Regression after removal of field lookup cache
`:app:minifyVariantWithR8` throws a NullPointerException in AGP 7.4.0-beta02
R8: ClassNotFoundException when -allowaccessmodification
Add support for context receivers in metadata
java.lang.VerifyError: Verifier rejected class androidx.compose.ui.graphics.colorspace.o: void androidx.compose.ui.graphics.colorspace.o.(java.lang.Object) failed to verify: void androidx.compose.ui.graphics.colorspace.o.(java.lang.Object): [0x0] cannot access instance field java.lang.Object androidx.compose.ui.graphics.colorspace.n.a from object of type Precise Reference: androidx.compose.ui.graphics.colorspace.o
AGP 7.4.0/7.3.1 - Attempt to enqueue an action in a non pushable enqueuer work list
Minifying Renderscript code: huge performance drop when upgrading AGP from 7.3.1 to 7.4.0

Android Gradle plugin 8.0.1

Fixed Issues
Shrinker (R8)
Error: "No VersionRequirement with the given id in the table" after upgrading AGP 7.2.2 -> 7.4.0
R8 NullPointerException at markTypeAsLive AGP 7.4.1
[R8 4.0.53] Hard class verification failure on Android 11

Android Gradle plugin 8.0.2

Fixed Issues
Shrinker (R8)
R8 fails during Compose build with ArrayIndexOutOfBoundsException
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