在将 Android Studio更新到3.1后,我在加载新的模板项目时遇到错误. 尝试使用和不使用此选项,但没有用: maven { url "https://maven.google.com"} 在构建期间,我看到以下消息: Caused by: org.gradle.int
尝试使用和不使用此选项,但没有用:
maven { url "https://maven.google.com" }
在构建期间,我看到以下消息:
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.android.tools.build:gradle:3.1.0. <6 internal calls> ... 128 more Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://dl/google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.pom' <21 internal calls> ... 133 more Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl/google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.0/gradle-3.1.0.pom'. <16 internal calls> Caused by: org.apache.http.conn.HttpHostConnectException: Connect to dl.google.com:433 [dl.google.com/216.58.199.142] failed
的build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 27 buildToolsVersion "27.0.3" defaultConfig { applicationId "com.example.am.myapplicationtest" minSdkVersion 19 targetSdkVersion 27 versionCode 1 versionName "1.0" //testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
截图供参考:
Gradle设置
我认为你的问题是由糟糕的网络造成的,因为:
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to dl.google.com:433 [dl.google.com/216.58.199.142] failed
我遇到了类似的问题,最后我发现根本原因是gradle的默认代理(不适用于Android Studio,但适用于gradle!)
我在gradle.properties中定义了自己的代理设置,但是当我在Android Studio中单击同步时,我的设置不适用并导致如下错误:
Error:Failed to resolve: com.android.support:appcompat-v7:27.0.1 Install Repository and sync project Open File Show in Project Structure dialog
解
最后我通过命令行构建我的应用程序并自己设置代理来解决我的问题,如下所示:
gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129
从Gradle proxy configuration获得这个,感谢Guillaume Berche.