AndroidStudio安裝及配置Gradle遇到的Error及解決辦法

1. 無法從網絡獲取 gradle-3.6.0.pom 文件

問題描述

具體表現爲 Sync Project with gradle file 之後報錯:
在這裏插入圖片描述
具體報錯信息爲:


FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'My Application'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:3.6.0.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:3.6.0.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.6.0/gradle-3.6.0.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.6.0/gradle-3.6.0.pom'.
               > Connection reset

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'My Application'.
	at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:80)
	at ...


* Get more help at https://help.gradle.org

CONFIGURE FAILED in 8s

解決辦法

可以看出主要是無法從https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.6.0/gradle-3.6.0.pom獲得資源文件。
我們可以改變AndroidStudio的默認配置,不用https。
具體打開 C:\Users\用戶名\.gradle\gradle.properties文件

systemProp.http.proxyHost=fodev.org
systemProp.https.proxyPort=8118
systemProp.https.proxyHost=fodev.org
systemProp.http.proxyPort=8118

註釋掉其中 https 的兩項。即改爲:

systemProp.http.proxyHost=fodev.org
# systemProp.https.proxyPort=8118
# systemProp.https.proxyHost=fodev.org
systemProp.http.proxyPort=8118

保存之後重新點擊AndroidStudio的File -> Sync Project with gradle file即可。

2. Android Studio設計編輯器不顯示

問題描述

Android studio design editor is unavailable until after a successful project sync
在這裏插入圖片描述
點擊AndroidStudio的File -> Sync Project with gradle file 之後發現報錯:
在這裏插入圖片描述

解決辦法

修改項目的Module.app的build.gradle文件 ,註釋掉測試的依賴包

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//    testImplementation 'junit:junit:4.12'
//    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
//    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

相關鏈接:

  1. Android studio3.53不能下載gradle-3.5.3.pom文件(read timed out)(Could not get resource …gradle-3.5.3.pom)
  2. 初用AndroidStudio建立第一個項目遇到的Error以及解決辦法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章