PC パソコン

Causes and Solutions for the Gradle “Could not Resolve” Error

When you build a project in Android Studio or Gradle, an error called “Could not resolve” may be displayed.

This error occurs when Gradle is unable to retrieve the required libraries or plugins from a repository. The causes vary and can include not only mistakes in dependency declarations, but also network issues, repository settings, version incompatibilities, and the Gradle cache.

This article explains the main causes of “Could not resolve” and the points you should check in Android Studio, step by step.

What Is Gradle’s “Could not resolve” Error?

In Gradle, the libraries and plugins required when building an application are retrieved from sources such as Maven Central and Google Maven Repository.

However, if the specified dependency cannot be found, an error like the following is displayed.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

For a specific library, the following message may also be displayed.

Could not resolve com.example:library:1.0.0.

In this case, Gradle itself is not necessarily broken. In many cases, it means that “Gradle does not know where to retrieve the specified library from” or “Gradle tried to retrieve it but failed.”

Cause 1: There Is a Problem with the Internet Connection

Gradle normally retrieves dependency libraries over the internet during a build. Therefore, if there is a problem with the network environment, “Could not resolve” may occur.

In particular, check for cases such as the following.

  • There is no internet connection
  • The Wi-Fi connection is unstable
  • A VPN is being used
  • Network communication is restricted at a company or school
  • The environment requires proxy settings

Even if websites can be opened in a browser, communication only to the repositories accessed by Gradle may be restricted by a firewall or other settings.

First, try restarting Android Studio or switching to another network, and then run Gradle Sync again.

Cause 2: Offline Mode Is Enabled

If Offline Mode is enabled in Android Studio or Gradle, Gradle does not access repositories on the internet and uses only libraries stored locally.

Therefore, if a newly added library does not exist in the cache, “Could not resolve” may occur.

Check the Gradle settings in Android Studio, and if Offline Mode is enabled, disable it before running Gradle Sync.

Cause 3: The repositories Configuration Is Incomplete

Gradle uses repositories to specify which repositories should be searched for libraries.

In Android applications, google() and mavenCentral() are commonly used.

repositories {
    google()
    mavenCentral()
}

If the required repository is not configured, Gradle cannot find a library even if the library itself exists.

In recent Android Studio projects, repositories may be managed in settings.gradle or settings.gradle.kts.

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

Cause 4: The Library Name or Version Is Incorrect

“Could not resolve” may also occur if the library name or version written in build.gradle is incorrect.

dependencies {
    implementation 'com.example:library:1.0.0'
}

Gradle dependencies are generally specified in the following format.

group:name:version

For example, if the version number is changed to one that does not exist, Gradle cannot find that library in the repository.

If the error appears immediately after adding a library, first check the spelling and version number of the dependency you added, as this can make it easier to identify the cause.

Cause 5: An Old Repository Is Being Used

In older Android projects, jcenter() may be configured.

repositories {
    jcenter()
}

Today, many libraries have moved to Maven Central, so when building an old project, it may become impossible to retrieve dependencies.

If possible, change the configuration to something like the following.

repositories {
    google()
    mavenCentral()
}

However, some older libraries have not moved to Maven Central, so simply changing the configuration may not solve the problem.

Cause 6: There Is a Problem with the Gradle Cache

Dependency libraries that have already been downloaded are stored in the Gradle cache.

If cached files become corrupted or are saved in an incomplete state, dependency resolution may fail even when the configuration is correct.

In that case, you can retrieve the dependencies again by running the following command from the terminal.

./gradlew build --refresh-dependencies

On Windows, it is normally as follows.

gradlew.bat build --refresh-dependencies

Rather than clearing the cache from the beginning, it is recommended to try this when the cause is still unknown even after checking the repository settings and version numbers.

Cause 7: Gradle, Android Gradle Plugin, and Java Versions Are Incompatible

In Android Studio, not only Gradle but also Android Gradle Plugin (AGP) and Java (JDK) versions have compatibility requirements.

After updating Android Studio or when opening an older project, the combination of versions may become incompatible, causing dependency resolution or plugin retrieval to fail.

In particular, check the following files.

  • gradle-wrapper.properties
  • build.gradle
  • build.gradle.kts
  • settings.gradle
  • libs.versions.toml

If you changed Android Studio, Gradle, AGP, or JDK immediately before the error occurred, check version compatibility.

Cause 8: The Plugin Cannot Be Retrieved

“Could not resolve” can occur not only with ordinary libraries but also with Gradle plugins.

Plugin [id: 'com.android.application', version: 'x.x.x'] was not found

In this case, check the repository settings in pluginManagement.

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

Because google() is important for the Android Gradle Plugin, check whether it is missing from the configuration.

Cause 9: A Temporary Repository Failure

Even if there is no problem with the configuration, temporary communication failures at Maven Central or Google Maven Repository may prevent libraries from being retrieved.

In this case, waiting for a while and then running Gradle Sync or the build again may solve the problem.

If the same project had been building normally until now and the error suddenly occurs even though you did not change the source code or Gradle configuration, consider the possibility of a temporary network or repository-side problem.

Solutions to Check First

If you do not know the cause, checking the following in order can be efficient.

  1. Check the internet connection
  2. Check whether Offline Mode is enabled
  3. Run Gradle Sync again
  4. Check google() and mavenCentral()
  5. Check the name and version of the library you added
  6. Look at what appears immediately after “Could not resolve” in the error message
  7. Check compatibility between Gradle, AGP, and JDK
  8. Try --refresh-dependencies

Check the Entire Error Message

The words “Could not resolve” alone may not reveal the actual cause.

In a Gradle error, a more specific cause is displayed below it.

Could not resolve com.example:library:1.0.0.

Could not get resource

https://repo.example.com/...
Could not GET ... Read timed out

In this example, the actual cause may not be the library name itself, but a communication timeout.

On the other hand, if a message like the following is displayed, suspect the version or repository settings.

Could not find com.example:library:1.0.0.

Rather than looking only at the single line saying “Could not resolve,” checking the error details displayed immediately after it is an important point when identifying the cause.

Difference Between “Could not find” and “Could not resolve”

Gradle may also display a similar error called “Could not find.”

Broadly speaking, “Could not resolve” represents the overall state in which a dependency could not be resolved, and specific reasons such as “Could not find” or “Could not GET” may be displayed underneath it.

Could not resolve com.example:library:1.0.0.
Required by:
    project :app

Could not find com.example:library:1.0.0.

In this case, Gradle was unable to find the specified library in the repository.

Summary

Gradle’s “Could not resolve” error is displayed when Gradle is unable to correctly resolve the dependencies of required libraries or plugins.

The main causes include network failures, Offline Mode, insufficient repository settings, nonexistent library versions, the Gradle cache, and incompatibilities between Gradle and AGP versions.

When the error occurs, do not judge the cause only from the “Could not resolve” part. Checking detailed messages displayed below it, such as Could not find, Could not GET, and timeout, can make it easier to narrow down the cause.

In particular, if the error appears immediately after adding a library, check the dependency declaration. If it appears immediately after updating Android Studio or Gradle, check version compatibility, which can reduce the time required to solve the problem.