No cached version of gradle

2019-01-15 14:15发布

问题:

I am getting this error when syncing gradle. I am pretty new to gradle so can't figure out what is the problem exactly?

Error:No cached version of com.android.tools.build:gradle:0.10.1 available for offline mode.

When I go to Setting->Gradle, I have offline mode ticked off and using default gradle wrapper.

回答1:

In my case I also had an additional "offline switch" to the one in Gradle.

Go to:

File > Settings > Build, Execution, Deployment > Compiler

There I've removed the --offline in Command-line Options. Earlier I was trying to speed up Android Studio a bit and this was one of the changes I had made.

Everything was fine after a restart then (and I have re-enabled both offline parts).



回答2:

This problem occurs, if you have offline mode switched on in your IDE and let the IDE upgrade your build file to use 0.10.1 of the gradle plugin (that is needed for the new AS version. Since you have never build with this version, it cannot be found in the offline cache.

Go to File->Settings->Gradle (under Project Settings on the top) and disable the check in front of Offline Work (Section 'Global Gradle settings' at the bottom). Now it can download the version with the next build and afterwards you are free to use offline mode again, if you wish so.



回答3:

Disable offline mode to solve this error.

In Android studio:

File -> Other Settings -> Default Settings -> Build,Execution,Deployment -> Build Tools -> Gradle

Then uncheck Offline work and sync again.

Hope your issue will resolved.



回答4:

I had the same problem in Android Studio v3.2.1.

This is working for me.

I updated Gradle version in build.gradle

 dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'//same as Android Studio vesion           
 }

and changed distributionUrl in gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

to

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip