Gradle is failing on syncing my project in the new Android Studio 2.0

Brian picture Brian · Apr 8, 2016 · Viewed 73.2k times · Source

I have just upgraded (i.e., installed a full new version) my Android Studio from 1.5 to 2.0. The upgrade seemed to go smoothly, but I am having trouble with my project when I open it, when Gradle is syncing my project.

After Gradle sync runs for a couple of minutes I get this error:

Failed to sync Gradle project MyProject
    Unknown host 'jcenter.bintray.com'. You may need to adjust the proxy settings in Gradle.
    Error:  Enable Gradle "offline mode' and sync project
            Learn about configuring HTTP proxies in Gradle

So, I click on the link that says:

Enable Gradle "offline mode' and sync project

Then Gradle spins for a second or two, and I now have this message:

Failed to sync Gradle project MyProject
    Error: No cached version of com.android.tools.build:gradle:1.3.0 available for offline mode.
           Disable Gradle 'offline mode' and sync project

So, I click on this link:

Disable Gradle 'offline mode' and sync project

And I am back to my first error again.

The machine I am working on is 100% off line. It does not have, nor will it ever have any kind of network connection whatsoever. I figure I need to disable some kind of check that requires the internet, but I am not sure what. Is this fixable, or do I have to downgrade back to Android Studio 1.5?

UPDATE

I am also getting this error message:

Gradle sync failed: Unknown host 'services.gradle.org'. You may need to adjust the proxy settings in Gradle.

Answer

Brian picture Brian · Apr 8, 2016

Ok, I fixed my issue so I wanted to post how I did it in case somebody else runs into this situation.

I was googling around and found a statement regarding working offline with Android Studio that read:

You can, however you won't be able to use any Gradle dependency. Gradle search into the repositories for dependencies using internet, so if you're completely unable to work online. Try not to include anything in the Gradle files, if you do, you'll have to sync it and it'll fail. Bascially just don't touch Gradle files and you'll be good to go.

So, I looked at my gradle files, specifically the build.gradle for the Project (not for the Module). Once there, I noticed a line:

dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0'
}

So, I replaced 1.3.0 with 2.0.0 and the project built just fine.

I hope this helps somebody else in the future. Good luck.