问题描述
我刚刚将我的 Android Studio 从 1.5 升级(即安装了全新版本)到 2.0.升级似乎很顺利,但是当我打开项目时,当 Gradle 正在同步我的项目时,我遇到了问题.
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.
Gradle 同步运行几分钟后,我收到此错误:
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
然后 Gradle 旋转一两秒,我现在收到了这样的信息:
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.
我正在使用的机器 100% 离线.它没有,也永远不会有任何类型的网络连接.我想我需要禁用某种需要互联网的检查,但我不确定是什么.这是否可以修复,还是我必须降级回 Android Studio 1.5?
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?
更新
我也收到此错误消息:
Gradle sync failed: Unknown host 'services.gradle.org'. You may need to adjust the proxy settings in Gradle.
推荐答案
好的,我解决了我的问题,所以我想发布我是如何做到的,以防其他人遇到这种情况.
Ok, I fixed my issue so I wanted to post how I did it in case somebody else runs into this situation.
我在谷歌上四处搜索,发现了一个声明关于使用 Android Studio 离线工作阅读:
I was googling around and found a statement regarding working offline with Android Studio that read:
您可以,但是您将无法使用任何 Gradle 依赖项.Gradle 使用 Internet 在存储库中搜索依赖项,因此如果您完全无法在线工作.尽量不要在 Gradle 文件中包含任何内容,如果这样做,您将不得不同步它并且它会失败.基本上不要碰 Gradle 文件就可以了.
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.
所以,我查看了我的 gradle 文件,特别是项目的 build.gradle(不是模块).到了那里,我注意到一行:
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'
}
所以,我将 1.3.0
替换为 2.0.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.
这篇关于Gradle 在新的 Android Studio 2.0 中同步我的项目失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!