AndroidStudio安装及配置Gradle遇到的Error及解决办法

1. 无法从网络获取 gradle-3.6.0.pom 文件

问题描述

具体表现为 Sync Project with gradle file 之后报错:
AndroidStudio安装及配置Gradle遇到的Error及解决办法_第1张图片
具体报错信息为:


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安装及配置Gradle遇到的Error及解决办法_第2张图片
点击AndroidStudio的File -> Sync Project with gradle file 之后发现报错:
AndroidStudio安装及配置Gradle遇到的Error及解决办法_第3张图片

解决办法

修改项目的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以及解决办法

你可能感兴趣的:(Android,android,studio,gradle)