Android Studio Gradle:错误:执行任务“:app:processDebugGoogleServices”失败。>找不到与包匹配的客户端。

130

我正在尝试按照Google给出的示例,将我的Google Play服务依赖升级到8.4.0,但是我遇到了以下错误('com.example.exampleapp'是我应用程序包名称的替换):

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

项目 build.gradle 文件:

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

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

allprojects {
    repositories {
        jcenter()
    }
}

应用程序的模块 app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.exampleapp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    useLibrary 'org.apache.http.legacy'

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.exoplayer:exoplayer:r1.5.2'
    compile 'com.google.android.gms:play-services-auth:8.4.0'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
    compile('com.mapbox.mapboxsdk:mapbox-android-sdk:3.0.0@aar') {
        transitive = true
    }
    compile files('libs/commons-lang3-3.3.2.jar')
}

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

gradle-wrapper.properties:

#Fri Jan 01 08:23:56 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
任何想法为什么gradle无法识别我的应用程序包名称?
编辑:

好的,这次我收到了不同的错误。

根据Shawn Thye提供的链接,我在app/build.gradle底部添加了以下内容:

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

除了我之前列出的内容之外,我还遇到了这个错误:

Information:Gradle tasks [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
/Users/user/Documents/AndroidStudio/ExampleApp/app/build.gradle
Error:(1, 1) A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > Gradle version 2.10 is required. Current version is 2.8. If using the gradle wrapper, try editing the distributionUrl in /Users/user/Documents/AndroidStudio/ExampleApp/gradle/wrapper/gradle-wrapper.properties to gradle-2.10-all.zip
Information:BUILD FAILED
Information:Total time: 0.921 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

以及Gradle控制台:

Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources]

Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/user/Documents/AndroidStudio/ExampleApp/app/build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > Gradle version 2.10 is required. Current version is 2.8. If using the gradle wrapper, try editing the distributionUrl in /Users/user/Documents/AndroidStudio/ExampleApp/gradle/wrapper/gradle-wrapper.properties to gradle-2.10-all.zip

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.211 secs

然后,我按要求将gradle-wrapper.properties更改为"gradle-2.10-all",结果出现了以下错误:

Information:Gradle tasks [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources]
google-services plugin could not detect any version for com.google.android.gms, default version: 8.3.0 will be used.
please apply google-services plugin at the bottom of the build file.
:clean
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library
:app:prepareComAndroidSupportCardviewV72311Library
:app:prepareComAndroidSupportDesign2311Library
:app:prepareComAndroidSupportGridlayoutV72311Library
:app:prepareComAndroidSupportRecyclerviewV72311Library
:app:prepareComAndroidSupportSupportV42311Library
:app:prepareComDigitsSdkAndroidDigits192Library
:app:prepareComFacebookAndroidFacebookAndroidSdk470Library
:app:prepareComGoogleAndroidExoplayerExoplayerR152Library
:app:prepareComGoogleAndroidGmsPlayServicesAuth840Library
:app:prepareComGoogleAndroidGmsPlayServicesBase840Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement840Library
:app:prepareComGoogleAndroidGmsPlayServicesMaps840Library
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement830Library
:app:prepareComMapboxMapboxsdkMapboxAndroidSdk230Library
:app:prepareComTwitterSdkAndroidTweetComposer102Library
:app:prepareComTwitterSdkAndroidTweetUi180Library
:app:prepareComTwitterSdkAndroidTwitter1110Library
:app:prepareComTwitterSdkAndroidTwitterCore162Library
:app:prepareIoFabricSdkAndroidFabric1310Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:processDebugManifest
:app:fabricGenerateResourcesDebug
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
Found com.google.android.gms:play-services-auth:8.4.0, but version 8.3.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-maps:8.4.0, but version 8.3.0 is needed for the google-services plugin.
:app:processDebugGoogleServices FAILED
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 8.3.0.
Information:BUILD FAILED
Information:Total time: 5.724 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

还有Gradle控制台:

Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources]

Configuration on demand is an incubating feature.
google-services plugin could not detect any version for com.google.android.gms, default version: 8.3.0 will be used.
please apply google-services plugin at the bottom of the build file.
Incremental java compilation is an incubating feature.
:clean
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library
:app:prepareComAndroidSupportCardviewV72311Library
:app:prepareComAndroidSupportDesign2311Library
:app:prepareComAndroidSupportGridlayoutV72311Library
:app:prepareComAndroidSupportRecyclerviewV72311Library
:app:prepareComAndroidSupportSupportV42311Library
:app:prepareComDigitsSdkAndroidDigits192Library
:app:prepareComFacebookAndroidFacebookAndroidSdk470Library
:app:prepareComGoogleAndroidExoplayerExoplayerR152Library
:app:prepareComGoogleAndroidGmsPlayServicesAuth840Library
:app:prepareComGoogleAndroidGmsPlayServicesBase840Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement840Library
:app:prepareComGoogleAndroidGmsPlayServicesMaps840Library
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement830Library
:app:prepareComMapboxMapboxsdkMapboxAndroidSdk230Library
:app:prepareComTwitterSdkAndroidTweetComposer102Library
:app:prepareComTwitterSdkAndroidTweetUi180Library
:app:prepareComTwitterSdkAndroidTwitter1110Library
:app:prepareComTwitterSdkAndroidTwitterCore162Library
:app:prepareIoFabricSdkAndroidFabric1310Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:processDebugManifest
:app:fabricGenerateResourcesDebug
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
Found com.google.android.gms:play-services-auth:8.4.0, but version 8.3.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-maps:8.4.0, but version 8.3.0 is needed for the google-services plugin.
:app:processDebugGoogleServices FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 8.3.0.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 5.724 secs

它在构建文件底部要求google-services插件,但它已经存在,并要求我再次运行8.3.0......因为现在只有这一点有效......


我自从创建项目以来就没有重命名或重构过它。但是在上述代码中,“com.example.exampleapp”是我的实际应用程序包名称的替换。 - sean
你解决了吗?我也遇到了同样的问题。 - dejavu89
很遗憾,目前还没有。我暂时回退到8.3.0版本... - sean
你能发布完整的logcat吗?看起来这不是你收到的错误的底线,可能还有更多的信息。 - gerardnimo
有更新吗?我也遇到了这个问题。 - Jill
显示剩余3条评论
25个回答

172
"client": [
{
  "client_info": {
    "mobilesdk_app_id": "9:99999999:android:9ccdbb6c1ae659b8",
    "android_client_info": {
      "package_name": "[packagename]"
    }
  }

package_name 必须与您的清单文件中的相匹配。您可以在下面的示例图片中找到 google-services.json 文件。

这里输入图片描述


谢谢,这正是我的情况。 - Leo DroidCoder
解决了我的问题。 - X09
问题解决了!谢谢! - CodeAlo
问题出在这里,“google-services.json”,正如你所提到的...谢谢 :) - Hossein Mansouri
谢谢,你节省了我很多时间。 - Umair
请大家检查是否需要单独的google-services.json文件。我的文件包含了2个产品风格的所有信息,所以我将其放在目录/app/中,不必为所有复杂的文件夹结构而苦恼。 - Benjamin Heinke

100

简单易行 在我的情况下,可以通过以下方法解决:

enter image description here

确保您的包名称在清单文件中与gradle应用程序ID相同。


4
这对我来说是真正的解决方案!谢谢 Hiren。 - Chris - Jr
14
在我的情况中,google-services.json 文件的包名不正确。 - sandeepd
如果我的回答有帮助且正确,请将其标记为“真”。 - Hiren
在我的情况下,另一个 google-services.json 文件藏在 app\src\debug 文件夹下。更新它以及所有其他文件解决了这个问题。 - CaptainNemo
解决了我的问题。 - Soufiane
显示剩余3条评论

36

这是一个检查是否上述修复问题的最终方案。不错,@Lord Flash - DJphy

22

解决了获取异常问题

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process Make sure to call FirebaseApp.initializeApp(Context) first.

在FirebaseInstanceId.getInstance().getToken()中。

检查package_name是否与applicationId完全匹配。 1)build.gradle

defaultConfig {
        applicationId "build.gradle.exactly.matches.json"
...
}

应当精确地匹配 2) google-services.json

{
      "client_info": {
        "mobilesdk_app_id": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
        "android_client_info": {
          "package_name": "build.gradle.exactly.matches.json"
        ....


21

当我尝试构建我的调试版本时,发生了与我完全相同的错误。我解决问题的方法是更改我的调试版本的google-services.json。 我原来的字段有一个名为client_id的字段,其值为android:com.example.exampleapp,我只需删除前缀中的android:并将其保留为com.example.exampleapp,之后我的gradle构建成功。

希望这可以帮到您!

编辑

我刚刚在我的google-services.json中添加回了android:前缀,并且它继续正常工作。 不确定发生了什么,但我能够使用上述解决方案解决我的问题。


无论如何,我仍然会收到相同的错误。谢谢! - sean
2
在Gradle Wrapper中将版本从2.8更改为2.10,然后执行文件->无效缓存/重启 - piotrek1543
所以这并不是一个确切的答案。我并不是因为你的努力而将其投票降低。但如果你有更好的答案,那将会是一个巨大的帮助。 - Shubham AgaRwal
在我的清单文件和 google-services.json 文件中,包名不同。非常出色! - Oleg Ushakov
优秀的答案。根据processGoogleDebugServices的错误,我也怀疑是这样。 - zooter
一个后续问题——你实际上需要在 Google 内部做出任何更改吗? - zooter

15

修复方法:

找不到与包名 'com.example.exampleapp' 匹配的客户端:

您应该从这里获取适用于您的包的有效的 google-service.json 文件。

修复版本冲突问题,可以通过升级 google-services 插件的版本(有关最新版本的信息可在此处查看)或将 com.google.android.gms 的版本更新为 8.3.0:

请将 apply plugin: 'com.google.gms.google-services' 移动到 app 的 gradle.build 文件的末尾。 示例:

dependencies {
    ...
}
apply plugin: 'com.google.gms.google-services'

10
我在使用Firebase时遇到了问题,我认为不同的包(package)导致了这个问题。

我通过在Firebase控制台中添加新应用程序的包(package),并重新下载google-services.json文件来解决了这个问题。 图片描述 图片描述 图片描述 图片描述

6

在Android Studio中打开google-services.json文件,我们可以看到一个JSON对象,并且在“client” JSON数组中包含以下项目:

"client_id": "android:您的包名", "package_name": "您的包名",

请确认您的包名并继续操作。


5

你的 google-services.json 包名称必须与你的 build.gradle 应用程序ID(applicationId "你的包名称")匹配。


5
我使用以下配置取得了成功:

我找到了成功的方法:

classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
//or use
//classpath 'com.android.tools.build:gradle:2.0.0-alpha6'

and

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

使用8.40 Google Play服务。无论distributionUrl是否为2.10,Alpha5和Alpha6都会出现与您相同的2.8错误。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接