Skip to content

[Tests] Gradle tests fail with AGP 8.5.0 and compileSdk 36 — configuration-cache serialization error #11042

@simonrozsival

Description

@simonrozsival

Summary

The BuildMultipleModules(MonoVM) test in AndroidGradleProjectTests.cs fails with a Gradle configuration-cache serialization error. The root cause is a version mismatch between the hardcoded default AGP version (8.5.0) and the dynamically derived compileSdk (36).

Failing Build

Root Cause

The test infrastructure has two values that have drifted apart:

  1. AgpVersion — hardcoded default of "8.5.0" in AndroidGradleProject.cs:19
  2. CompileSdk — dynamically derived from AndroidLatestStableApiLevel (currently 36) in AndroidGradleModule.cs:18

AGP 8.5.0 was only tested up to compileSdk 34. When used with compileSdk 36 and Gradle configuration-cache enabled, AGP hits a serialization bug.

Build Log Errors

AGP warning:

WARNING: We recommend using a newer Android Gradle plugin to use compileSdk = 36

This Android Gradle plugin (8.5.0) was tested up to compileSdk = 34.

Configuration-cache crash:

FAILURE: Build failed with an exception.

Configuration cache state could not be cached: field `elements` of
`org.gradle.internal.serialize.codecs.core.ResolutionBackedFileCollectionSpec`
bean found in field `__externalLibJavaRes__` of task
`:TestAppModule:mergeDebugJavaResource` of type
`com.android.build.gradle.internal.tasks.MergeJavaResourceTask`:
error writing value of type 'java.util.ArrayList'

MSBuild error:

error MSB6006: "gradlew" exited with code 1.

References

Proposed Fix

Bump the default AgpVersion (and corresponding Gradle version) to a version that supports the current compileSdk. The existing BindLibraryWithMultipleGradleVersions test already uses AGP 9.0.0 + Gradle 9.1.0 as a test case, so bumping the defaults to match would be the simplest fix:

// AndroidGradleProject.cs
public string AgpVersion { get; set; } = "9.0.0";

Alternatively, the default could be made dynamic based on CompileSdk, using AGP 8.5.0 for compileSdk ≤ 34 and AGP 9.0.0+ for compileSdk ≥ 35.

Notes

  • This is not specific to any PR — it affects any branch targeting main since AndroidLatestStableApiLevel moved to 36.
  • All public CI (Linux, macOS, Windows builds on dnceng-public) passes fine — this only affects the internal Xamarin.Android-PR pipeline which runs the MSBuild integration tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions