134

I received an error message while building a new Hello World project in Android Studio:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'MyApplication2'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:0.9.1.
     Required by:
         :MyApplication2:unspecified
      > No cached version of com.android.tools.build:gradle:0.9.1 available for offline mode.

BUILD FAILED

Android Studio version: 0.5.2

Gradle version: 0.9.1

I'm using a proxy connection to Internet.

MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
robin
  • 1,481
  • 2
  • 10
  • 4
  • Have you tried configuring your Android Studio to use the proxy server. You may want to see this http://stackoverflow.com/questions/18443208/androidstudio-gradle-proxy – blackpanther Mar 24 '14 at 11:10
  • Describe your "proxy connection to the internet". Clearly the initial cache isnt done as described here: http://stackoverflow.com/questions/20746071/failed-to-build-android-hello-world-application-in-offline-mode – RichieHH Mar 24 '14 at 11:11
  • Thanks for the solution, but now I'm getting an another problem. Failed to refresh Gradle project 'My Application 2' Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.9.1/gradle-0.9.1.pom'. Received status code 500 from server: Internal Server Error Enable Gradle 'offline mode' and sync project As said above comments, I have configured the proxy settings in the Android Studio. – robin Mar 24 '14 at 11:22

11 Answers11

214

With the new Android Studio 3.6 to toggle Gradle's offline mode go to View > Tool Windows > Gradle from the menu bar and toggle the value of Offline Mode that is near the top of the Gradle window.

enter image description here

enter image description here

jeprubio
  • 17,312
  • 5
  • 45
  • 56
205

Had the same error after updating Android Studio today. For me, it wasn't a matter of proxy settings:

  1. Uncheck "Offline work" in Android Studio 0.6.0:

    File->Settings->Gradle->Global Gradle Settings

    or in OSX:

    Preferences->Gradle->Global Gradle Setting

    or in more recent versions:

    File->Settings->Build, Execution, Deployment->Build tools->Gradle

  2. Resync the project, for example by restarting the Android Studio

  3. Once synced, you can check the option again to work offline.

(Only tested in Gradle version 0.11... and Android Studio version 0.6.0 Preview)

EDIT : Added paths for different versions/platforms (as mentioned by John Ballinger and The_Martian). Not yet verified.

friedrich
  • 2,095
  • 1
  • 11
  • 12
  • 21
    ON OSX: Uncheck "Offline work" in Android Studio >Preferences>Gradle>Global Gradle Settings – John Ballinger Jun 10 '14 at 03:19
  • 2
    Android Studio will start downloading files after that, so probably a good idea to wait till it finishes (v0.8.1). – knownasilya Jul 01 '14 at 13:43
  • 1
    I was getting this error when I tried to include Crashlytics and this solution worked perfectly. – Psypher Sep 08 '14 at 12:04
  • 1
    Offline work is rather located in File->Settings->Build, Execution, Deployment->Build tools->Gradle and not in the path you mentioned. – The_Martian Apr 26 '16 at 18:11
  • @friedrich I have a question: I copy the same version jar into dir ./gradle/caches/modules-2/files-2.1, and use offline mode also happen this error. what different once synced,and then use offline again – Carl Mar 27 '19 at 10:15
  • These paths do not exist for android studio 4. I can't find how to toggle offline mode in android studio 4. I turned it on in android studio 3.6 and upgraded to 4.0 and I am lost now – GunJack Jun 01 '20 at 03:44
  • I tried File->Settings->Build, Execution, Deployment->Build tools->Gradle but I don't see any off line check box – Laura Galera May 18 '21 at 18:10
64

Please follow below steps :

1.Open Your project.

2.Go to the Left side of the Gradle button.

3.Look at below image.

enter image description here

4.Click button above image show.

5.if this type of view you are not in offline mode.

6.Go to Build and rebuild the project.

All above point is work for me.

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
42

Just happened to me after upgrading to Android Studio 3.1. The Offline Work checkbox was unchecked, so no luck there.

I went to Settings > Build, Execution, Deployment > Compiler and the Command-line Options textfield contained --offline, so I just deleted that and everything worked.

setting screenshot

m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
Martin Melka
  • 7,177
  • 16
  • 79
  • 138
24

I had same error...Please Uncheck the offline work in Settings.

File => Settings => Build, Execution, Deployment => Build Tools => Gradle => Offline Work

After Gradle Sync Finished, Please Restart Your Android Studio.

Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
6

enter image description here

  1. click on right second one image .
  2. file -> invalidate and Restart .

It will work for me please try !!!

priti
  • 892
  • 9
  • 9
4

For mac, Uncheck Offline Work from Preference -> Build, Execution, Deployment -> Build Tools -> Gradle -> Global Gradle Settings

tip: cmd+, to open Preference via shortcut key

touhid udoy
  • 4,005
  • 2
  • 18
  • 31
1

Since you mention you have a proxy connection I will tell you what worked for me: I went to properties (as friedrich mentioned) ensuring the Offline Work was unchecked. I opened up the gradle.properties file in the IDE and added my proxy settings. Here's a generic version:

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

Then at the top of the properties file in the IDE there was a "Try Again" link which I clicked. That did it.

Tony D
  • 1,531
  • 17
  • 29
1

New Solution (Due to the redoing of Android Studio)

File -> Settings -> Build, Execution, Deployment -> Compliler

In the line Command-line Options delete: --offline

user_MGU
  • 978
  • 11
  • 11
0

In my case I get the same error title could not resolve all dependencies for configuration

However suberror said, it was due to a linting jar not loaded with its url given saying status 502 received, I ran the deployment command again, this time it succeeded.

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73
0

For new UI, click the icon cloud to enable/disable offline mode.

enter image description here