With Android Gradle Plugin 9.1.0, a project combining core library desugaring with minification for Android tests can fail because Gradle detects a cycle between l8DexDesugarLibUiTest and minifyAndroidTestWithR8. This is a known AGP task-graph regression rather than a circular dependency in application modules. The fix arrived in AGP 9.4.0-alpha05 and is included in stable AGP 9.4.0.
Representative error
Circular dependency between the following tasks:
:app:l8DexDesugarLibUiTest
\--- :app:minifyAndroidTestWithR8
\--- :app:l8DexDesugarLibUiTest (*)
The module name and test build type can change the :app and UiTest portions. The distinctive signature is a cycle between the L8 desugared-library task and the R8 minification task for an Android Test variant.
Cause
Google Issue Tracker #491718901 documents AGP 9.1.0 creating an incorrect circular dependency when desugaring is enabled, preventing instrumented tests from running. The cycle is generated in AGP’s build task graph between l8DexDesugarLibUiTest and minifyAndroidTestWithR8; it is not evidence that the application’s source modules reference one another cyclically.
Conditions and affected versions
- The project uses Android Gradle Plugin 9.1.0.
- Core library desugaring is enabled.
- R8 minification is enabled for an Android Test variant.
- An instrumented-test build or related Android Test task is executed.
Google lists the correction in AGP 9.4.0-alpha05, released with Android Studio Quail 4 Canary 1. Stable Android Studio Quail 4 ships with AGP 9.4.0, so upgrading to a compatible AGP 9.4.0 or later release is now the preferred solution.
Recommended solution
- Record the current AGP, Gradle, and JDK versions and commit project changes.
- Upgrade AGP to 9.4.0 or later. Preview test environments can use 9.4.0-alpha05 or a later build containing the fix.
- Align Gradle and the JDK with the AGP compatibility requirements.
- Sync, stop existing Gradle daemons, and rerun the affected instrumented-test task.
[versions]
agp = "9.4.0"
./gradlew --stop
./gradlew :app:connectedDebugAndroidTest --stacktrace
Alternatives when an upgrade is not possible
- If the problem began immediately after moving to AGP 9.1.0, temporarily return to the previously working AGP release and restore compatible Gradle and JDK versions.
- If minification is not required for the test variant, disable Android Test minification on a diagnostic branch and check whether the task cycle disappears.
- Do not disable core library desugaring unless you have verified that the application does not rely on it, because doing so can change Java API compatibility on older devices.
Disabling minification or desugaring is a diagnostic or temporary workaround, not Google’s permanent fix. If tests must match release-like settings, use an AGP version containing the correction.
How to verify the fix
- Confirm that
./gradlew :app:taskscompletes without the circular-dependency error. - Run the previously failing instrumented-test task with
--stacktrace. - Verify that the
l8DexDesugarLib...TestandminifyAndroidTestWithR8tasks complete and produce the test APK. - Confirm that tests run on a device or emulator and Gradle ends with
BUILD SUCCESSFUL.
Cautions
Other Gradle configurations can also produce a “Circular dependency” message. If the reported cycle does not include these two generated tasks, investigate custom tasks and module dependencies separately. Updating AGP without a compatible Gradle version can also introduce a different sync failure, so check Google’s compatibility guidance before changing versions.
Summary
The cycle between l8DexDesugarLibUiTest and minifyAndroidTestWithR8 in AGP 9.1.0 is a known regression in the task relationship between desugaring and Android Test minification. Google introduced the fix in AGP 9.4.0-alpha05, and stable AGP 9.4.0 includes it. Upgrading to a compatible fixed AGP is preferable to permanently weakening test settings.
