81

At office, I am behind a proxy. The internet access is restricted.

So I performed a gradle sync at home and copied the folder ".gradle" present at C:\Users\username.gradle from my home PC to the same location on my office PC.

Now on my office PC, I set gradle in Android Studio to "Work Offline" but still whenever I try to perform a gradle sync, I get an error stating

Error: Could not download google-services.jar (com.google.gms:google-services:3.0.0): No cached version available for offline mode

However on digging through the ".gradle" folder I was able to locate the google-service.jar file at

C:\Users\username\.gradle\caches\modules-2\files-2.1\com.google.gms\google-services\3.0.0\32b833222c886ecfb37d79b1a05ce1eddb702db1

I am not sure how to proceed. Please help.

Martin Schröder
  • 4,176
  • 7
  • 47
  • 81
Mufaddal Gulshan
  • 1,223
  • 3
  • 11
  • 14

12 Answers12

124

I had to dig for this a long time in the 2019.2 version. This option has moved in the UI. It is now in the toolbar of the gradle tools:

intellij gradle toolbar

see JetBrains documentation at https://www.jetbrains.com/help/idea/jetgradle-tool-window.html#offline

Ocie Mitchell
  • 1,745
  • 2
  • 12
  • 20
  • 2
    @NevinChen i wanted to ditch it entirely, and use eclipse.. People are use to settings – Declan Nnadozie Sep 24 '19 at 10:59
  • 2
    Wow thanks for the find, I didn't even see the button. It was hidden since my Gradle sidebar was to narrow. – Sascha Dec 03 '19 at 12:52
  • Thanks! It switched to online mode! – Dennis Gloss Dec 17 '19 at 08:06
  • No, it shouldn't, this answer is for a different question entirely! The OP needs to work in offline mode due to restricted internet and is trying to get it to work. – Jonik Mar 25 '20 at 15:19
  • Well it solved _my_ problem, so I'm happy. Worth noting: the icon doesn't change when you click it other than to have the background change from grey to clear. That confused me for a bit. – Edward Falk Sep 16 '21 at 19:03
100

This Error occurs when in your Android Studio's Gradle Tools Offline Mode option is Enabled.

enter image description here

When Enabled it lookes like this.

enter image description here

To fix it, you can Disable mode by clicking on the option shown in below screenshot.

enter image description here

Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25
77

> Update: I heard Google Listened to the suggestion! and now in new android studio versions, when you start a new project, a popup will come with option to either build with gradle online or offline.. Great for you all..


You need to re-enable your gradle online mode

Google changed the location of doing this... After the latest version as at this time i am typing this answer, which is version below Android Studio 3.6.1 built on February 27, 2020

I have sent a message to the them so Google changes this in next update..Cos the new location confuses the Software engineers who are used to the old way of doing it... But for now follow these clear 2 steps to find it and toggle it Online or Offline easily..

  1. Just Go to the top-right hand corner of your SDK and click the vertical Gradle tab as circled in red in the my picture below... step1

  2. Then you Click this icon (which looks like a symbol in an electrical schematic circuit) on the gradle table that comes out.. As Circled in Red in my picture below.. Image of what you must toggle

Samuel Ewudzi Incoom
  • 1,802
  • 17
  • 17
24

Maybe helps someone. Just remove --offline in "Command-line Options:"

enter image description here

vmtrue
  • 1,724
  • 18
  • 36
17
  1. click on gradle on the right
  2. toggle offline mode
  3. try again (sync with gradle files)

enter image description here

Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
10

It seems that in newer versions of IntelliJ (I am on 2018.1) you may need to uncheck the Offline checkbox in Gradle preferences.

Gradle Prefences Screenshot

Jan Havel
  • 319
  • 3
  • 6
4

Just for reference 2019.1 Ultimate IntelliJ, go to Gradle -> Settings (a top-rightmost icon) -> Uncheck the Offline work in Global Gradle settings.

enter image description here

Gradle Tab not presented, go to View -> Tool Windows -> Gradle to show it first.

Hearen
  • 7,420
  • 4
  • 53
  • 63
  • 2019.2 ultimate looks entirely different when I open the gradle section and I don't see an offline section. Maybe I have this setting somewhere else. – Ocie Mitchell Aug 28 '19 at 21:34
  • in my case was a command-line options, take a look into it https://stackoverflow.com/a/59376069/2238515 – Almeida Dec 17 '19 at 14:13
2

I'm using android studio in MacBook

step 1 - Go to preferences by clicking android studio on the left uppermost corner.

step 2 - Go inside Build,Execution,Deployment.

step 3 - Finally select Gradle.

step 4 - then, uncheck offline work. Click apply then ok.

step 5- lastly try to sync once again.

Hope this will work because it works for me.

Raghib Arshi
  • 717
  • 8
  • 12
  • Thanks for posting these steps. Unfortunately, this is not available in the latest android studio. So we can follow this https://stackoverflow.com/a/59133393/2219406 – Mohamed Ibrahim Mar 26 '20 at 04:59
2

You can set startParameter.offline=false in your settings.gradle

Ernis A.
  • 141
  • 1
  • 3
1

Try running gradle with the --debug flag, in addition to the --offline flag. That will tell you exactly where it's looking for the files.

One possible reason for the error is that the path of the .gradle folder is different between your home and office PC, possibly because your username is different on each machine. The .gradle cache uses absolute paths (see .gradle/caches/modules-2/metadata-2.16/artifact-at-repository.bin for an example). This is a documented Gradle issue: https://discuss.gradle.org/t/copying-the-gradle-cache-to-another-machine/7546/13. If possible, use the same GRADLE_HOME at home and work to resolve the issue.

Stephen Rudolph
  • 1,385
  • 14
  • 20
0

How to configure gradle to work "offline" (using cached dependencies)

Uncheck the 'Offline work' under the Global Gradle settings fixes my issue.

Jason H
  • 369
  • 5
  • 5
0

first step would be to disable offline Gradle mode. if issue is still persist then might be one of your app dependency Gradle is not able to connect. check your all dependencies.

Hope it will help!!

Kishan Thakkar
  • 619
  • 6
  • 11