Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

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

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...