問題描述
我剛剛將我的 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 中同步我的項目失敗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!