【问题标题】:Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom'无法获取“https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom”
【发布时间】:2021-11-06 05:06:09
【问题描述】:

我是 Android Studio 的新手,每次尝试将项目与 gradle 同步时都会收到此错误。例如,我提供了对三个文件的引用。

1) 项目级 build.gradle 文件

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.myfirstapp"
        minSdk 24
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

2) Gradle 脚本 build.gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0-RC2"

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

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

3) gradle-wrapper.properties

#Fri Nov 05 11:37:25 IST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

我在 Windows 10 上使用 Android Studio Arctic Fox 2020.0.1 Patch 3

我得到的完整错误消息是

Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom'. Received status code 405 from server: Method Not Allowed

【问题讨论】:

  • 对我来说很好。闻起来像防火墙问题。
  • chrylis 你有解决办法吗?
  • 第 1 步:发布完整的错误消息,尤其包括可能显示“连接超时”之类的部分。
  • 是的,我添加了完整的错误信息
  • Chrylis 我在问题末尾添加了完整的错误消息,现在您能否为我提供解决方案,因为我无法开始使用 android studio。毕竟这是我的第一个项目。

标签: java android android-studio gradle


【解决方案1】:

好吧,看起来还不错,我只能猜测是连接问题。

尝试在浏览器中使用此链接https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.0.2/gradle-7.0.2.pom,以确保您可以连接到谷歌。

如果您可以访问该站点,那么您可能需要使用代理/vpn。

这样做的方法是下载psiphon并导航到设置,例如将本地端口设置为1234。

然后转到 Users/%USERNAME%/.gradle 并添加 gradle 属性,如下

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1234

systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1234

【讨论】:

  • 是的,我可以成功连接到 dl.google.com,是的,我想我需要一个代理,让我试试你的建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-07
  • 2020-11-01
  • 2019-04-09
  • 2019-06-11
  • 1970-01-01
  • 2020-11-10
  • 2019-03-15
相关资源
最近更新 更多