无法获取'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.0.1/google-services-4.0.1.pom'

时间:2019-01-17 08:39:45

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

在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
  • 版本版本: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'
}

2 个答案:

答案 0 :(得分:0)

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

// 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

答案 1 :(得分:0)

只需从Firebase实现中删除:15.0.0

implementation应该类似于:

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

否则一切似乎都很好!