Gradle中的Google Service下载失败

问题描述

按照Firebase Cloud Platform中指定的说明进行操作。在运行gradle构建时遇到此问题。

Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.gms:google-services:4.3.3.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/android/gms/google-services/4.3.3/google-services-4.3.3.pom
       - https://jcenter.bintray.com/com/android/gms/google-services/4.3.3/google-services-4.3.3.pom
     Required by:
         project :

build.gradle,并添加了工件。

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

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 16
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")
        classpath("com.android.gms:google-services:4.3.3")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS,Obj-C sources,Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

对该问题的任何输入都会有所帮助,已经检查了防火墙和代理问题。

解决方法

Android项目中有两个build.gradle文件。一个用于应用程序级别,另一个用于您的项目根级别。
为了正确设置Firebase,您必须在根级别(项目级别)Gradle文件(build.gradle)中编写如下代码:

buildscript {

  repositories {
    // Check that you have the following line (if not,add it):
    google()  // Google's Maven repository
  }

  dependencies {
    // ...

    // Add the following line:
    classpath 'com.google.gms:google-services:4.3.3'  // Google Services plugin
  }
}

allprojects {
  // ...

  repositories {
    // Check that you have the following line (if not,add it):
    google()  // Google's Maven repository
    // ...
  }
}

在模块(应用程序级)Gradle文件(通常为app / build.gradle)中,应用Google Services Gradle插件,如以下代码片段所示:

apply plugin: 'com.android.application'
// Add the following line:
apply plugin: 'com.google.gms.google-services'  // Google Services plugin

android {
  // ...
}

除了应用程序级文件外,您正在执行所有操作。尝试修复它,并告诉它是否有效。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...