Android Studio Gradle .pom文件下载错误

时间:2018-06-28 08:54:32

标签: java android maven gradle jcenter

我来自伊朗,我无法在没有代理的情况下使用gradle,但现在我也无法在没有代理的情况下使用gradle,我不知道为什么我要更改每件事,但仍然无法通过Cicsco Connection来帮助我,这是我的gradle文件 模块build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "test.example.test.com.test"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // google support library ---------------------------------------------------------------------
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:support-v13:27.1.1'
    implementation 'com.android.support:support-vector-drawable:27.1.1'

}

和项目gradle

    buildscript {

    repositories {
        google ()
        jcenter{ url "http://jcenter.bintray.com/" }
        maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google ()
        jcenter{ url "http://jcenter.bintray.com/" }
        maven { url 'http://repo1.maven.org/maven2' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我得到的错误

1 Cause: dl.google.com:443 failed to respond

2 org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'

3 Could not GET 'http://jcenter.bintray.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'

4 Could not GET 'http://repo1.maven.org/maven2/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom'.

2 个答案:

答案 0 :(得分:0)

我只需编辑gradle属性即可解决问题,我添加了代理,却忘记了我的问题

答案 1 :(得分:0)

Gradle有其自己的依赖管理系统,类似于maven。我认为gradle publish插件的一部分以某种方式得到了maven的支持(未经验证)。不管您不必担心那种深度,gradle都可以解决。您的问题是设置代理。您只需要在$ projectDir / gradle.properties中设置一些变量,例如:

#http proxy setup
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

这可用于下载不带代理的依赖项。如果要使用代理,则可以使用下面的代码代替上面的代码。

systemProp.https.proxyPort=3128
systemProp.http.proxyHost=192.168.16.2
systemProp.https.proxyHost=192.168.16.2
systemProp.http.proxyPort=3128

可以根据需要更改代理端口和主机。