【问题标题】:cannot sync gradle when adding "apply plugin: 'com.google.gms.google-services'" for Firebase Database为 Firebase 数据库添加“应用插件:'com.google.gms.google-services'”时无法同步 gradle
【发布时间】:2018-01-06 09:48:36
【问题描述】:

我是在 Android Studio 2.3.3 上进行 Android 应用开发的新手。我正在按照 Firebase 数据库指南连接到数据库。但是在进行同步时它失败了(见下面的错误)。很多人都在问同样的问题,但解决方案似乎对他们自己的 gradle 文件过于具体,所以我可以用它来修复我的应用程序。任何帮助将不胜感激:-)

Error:Execution failed for task ':app:processDebugGoogleServices'.
> No matching client found for package name 'com.example.lenovo.hereandthere'

build.gradle(项目:HereAndThere)

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

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.1.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

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

build.gradle(模块:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.lenovo.hereandthere"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

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

注意: enter image description here

【问题讨论】:

  • 添加google json服务文件
  • 嗨,Shubham,哪些文件,在哪里以及如何?
  • developers.google.com/android/guides/…你需要一个谷歌服务json文件才能使用谷歌服务插件
  • 它已经完成了。我已经上传了关于该文件的屏幕截图:“google-services.json”
  • 查看文件是包名是com.example.lenovo.hereandthere

标签: android android-studio firebase firebase-realtime-database android-studio-2.3


【解决方案1】:

找不到与包名称“com.example.lenovo.hereandthere”匹配的客户端

由于以下原因之一,可能会出现此问题:

  1. 不存在 google 服务 .json 文件
  2. 或 google 服务 .json 文件存在但放置在错误的位置。 check out this
  3. 或包名与google服务.json中提到的不同(人们通常不这样做,但不幸的是 是你的情况。)

【讨论】:

  • 好的,谢谢!我用正确的包名重新创建了一个新项目。我现在可以读写数据库了。真是太痛苦了。
猜你喜欢
  • 2020-08-29
  • 1970-01-01
  • 2018-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-20
相关资源
最近更新 更多