【问题标题】:Could not GET 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.0.1/google-services-4.0.1.pom'无法获取“https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.0.1/google-services-4.0.1.pom”
【发布时间】:2019-06-11 10:00:10
【问题描述】:

在 Firebase 身份验证(助手)中使用向您的应用添加 Firebase 身份验证时出错

同步选项卡中的错误显示为:

无法获取“https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.0.1/google-services-4.0.1.pom”。从服务器收到状态码 405:不允许方法 启用 Gradle“离线模式”并同步项目

我的 Android Studio 详细信息是:

  • Android Studio 3.2.1 版
  • Gradle 版本:4.6

build.gradle(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/android/android-tools' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.0.1'

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

build.gradle(应用)

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.nsc.suyog.myotp1"
        minSdkVersion 21
        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'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    testImplementation 'junit:junit:4.12'

    implementation 'com.google.firebase:firebase-auth:16.0.1:15.0.0'
}

【问题讨论】:

  • 您可以发布您的 build.gradle 文件(项目和应用程序)吗?
  • 是的。这个错误的原因是什么?
  • 您是否尝试更新所有版本,例如:classpath 'com.android.tools.build:gradle:3.3.0' classpath 'com.google.gms:google-services:4.2.0'
  • 如何更新它们?
  • 您的 Firebase 身份验证版本很奇怪,不是吗?试试最新的16.1.0

标签: android firebase android-studio gradle firebase-authentication


【解决方案1】:

尝试更改以下代码(项目):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        maven { url "http://jcenter.bintray.com"}
        maven { url 'https://dl.bintray.com/android/android-tools' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.2.0'

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

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

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

和(应用程序):

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.nsc.suyog.myotp1"
        minSdkVersion 21
        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'
        }
    }
}

android { lintOptions { abortOnError false }

    aaptOptions {
        cruncherEnabled = false

    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    testImplementation 'junit:junit:4.12'

    implementation 'com.google.firebase:firebase-auth:16.1.0'
}

同样在 gradle-wrapper.properties 中添加这一行或者如果已经存在其他值则更改:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

【讨论】:

  • 我已经按照你的说法改变了这个。不工作,仍然得到同样的错误。怎么办?
  • @Suyog 试试这个
  • 以上两个代码我已经复制并再次尝试。得到同样的错误。
  • 我有一行:distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 我是否需要将我的 android studio 更新到 3.3 以获取 gradle-4.10。 1-all.zip??
  • 试过了。没有效果:(你的 android studio 配置是什么??它对你有用吗?
【解决方案2】:

只需从 firebase 实现中删除 :15.0.0

implementation 应该是这样的:

implementation 'com.google.firebase:firebase-auth:16.1.0'

否则一切看起来都很好!

【讨论】:

  • 尝试使用16.1.0,因为没有名为16.0.1的版本
  • 我已经删除了整行: implementation 'com.google.firebase:firebase-core:16.0.1' 仍然出现同样的错误。版本更改不会产生错误。
  • 没有安装连接出现此错误。
  • 所以我认为错误在这一行,将其添加到 build.gradle 文件的末尾:apply plugin: 'com.google.gms.google-services'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-07
  • 2021-07-25
  • 1970-01-01
  • 2019-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多