gradle 'Could not find com.android.tools.build:gradle:X' after AGP upgrade
Fixes Gradle's could not find com.android.tools.build:gradle after an AGP upgrade. Use it when the Android Gradle Plugin artifact is missing from the declared repositories. Key trigger: the could not find line with the AGP coordinates. Not for dependency-resolution or duplicate-class errors.
TL;DR
Gradle cannot find the Android Gradle Plugin artifact because the Google Maven repository is not declared where the plugin is resolved. Add the google repository to the plugin management block (or the buildscript block on older setups), verify the AGP version exists, and sync again.
Error
gradle 'Could not find com.android.tools.build:gradle:X' after AGP upgradeSteps
Check where plugin repositories are declared: settings.gradle (pluginManagement block) or the root build file (buildscript block). Expected output: You see the repository list the AGP plugin resolves against.
Add the Google Maven repository if absent: google() in the pluginManagement repositories block. Expected output: The block lists the Google repository alongside the others.
Verify the AGP version exists: check the version against the published AGP releases. Expected output: The version string matches a real release.
Check Gradle is not in offline mode, then sync: ./gradlew help or a full sync. Expected output: Gradle downloads the plugin and configures the project.
Build: ./gradlew assembleDebug. Expected output: The build proceeds past plugin resolution.
When to use
- Gradle fails with could not find com.android.tools.build:gradle:X after an AGP upgrade
- The plugin version was bumped but the repository list was never updated for it
- A new checkout or CI machine fails while an old machine works (different init scripts or caches)
When not to use
- The failure is could not resolve all files for a configuration; that is dependency resolution, not plugin resolution
- The failure is duplicate classes; that happens much later in the build
- The AGP version is fine but the Gradle wrapper version is too old; upgrade the wrapper instead
Variant phrasings
Could not find the Android Gradle Plugin after bumping the version
The bump shape; the version is real but no declared repository serves it.
AGP plugin resolution fails on CI only
CI may use init scripts that override repositories; check the CI Gradle setup.
Plugin not found with an older settings.gradle layout
Older projects resolve plugins from the buildscript block; add the Google repository there.
Why it happens
The AGP artifact lives in Google's Maven repository, not the central one most projects default to. Plugin resolution uses the pluginManagement repositories, a separate list from the dependency repositories, so a project can resolve all its libraries fine while the plugin itself 404s. Upgrades expose it because the new version was never cached locally.
Edge cases
- Offline mode makes every plugin version "not found"; toggle it off before debugging repositories.
- Init scripts can inject or replace repository lists; check ~/.gradle/init.d on the failing machine.
- The Gradle wrapper version must support the AGP version; an incompatible pair fails with a different but nearby error.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstldSJfyq1IMPxWxiJ1s-Ag