Gradle无法在新的Android Studio 2.0中同步我的项目

Gradle无法在新的Android Studio 2.0中同步我的项目

问题描述:

我刚刚将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

所以,我单击此链接:

Disable Gradle 'offline mode' and sync project

我又回到了我的第一个错误.

And I am back to my first error again.

我正在使用的机器离线100%.它没有,也永远不会有任何类型的网络连接.我认为我需要禁用某种需要Internet的检查,但是我不确定是什么.这个可以解决吗,还是我必须降级到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依赖项.使用Internet在Gradle上搜索存储库中的依赖项,因此,如果您完全无法在线工作.尽量不要在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文件,特别是Project(而不是Module)的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'
}

因此,我用2.0.0替换了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.