当前位置:  开发笔记 > Android > 正文

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

如何解决《AndroidStudioGradle:错误:任务':app:processDebugGoogleServices'的执行失败.>找不到包的匹配客户端》经验,为你挑选了11个好方法。

我正在尝试按照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-2.10-all"的要求更改了gradle-wrapper.properties并得到了这个错误:

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 ......我将会这样做,因为那是唯一正常工作的...



1> 小智..:
"client": [
{
  "client_info": {
    "mobilesdk_app_id": "9:99999999:android:9ccdbb6c1ae659b8",
    "android_client_info": {
      "package_name": "[packagename]"
    }
  }

package_name必须匹配清单文件中的内容.google-services.json如果你查看下面的示例照片,你可以找到该文件.

在此输入图像描述



2> Hiren..:

Simpal很简单在我的情况下,它解决了如下

在此输入图像描述

确保mainifests文件中的pakage名称与gradle的applicationId相同.


在我的情况下,google-services.json没有正确的包名.
这对我来说是真正的解决方案!谢谢Hiren.

3> Tobias..:

切换口味时发生在我身上.

现在您还可以使用不同风格的google-services.json.

请参阅/sf/ask/17360801/



4> Alex Burov..:

解决了获得异常的问题

java.lang.IllegalStateException:此过程中未初始化默认FirebaseApp确保首先调用FirebaseApp.initializeApp(Context).

在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"
        ....



5> carotorrehdz..:

只有当我尝试构建我的调试构建类型时,才会发生同样的错误.我解决它的方法是更改​​我google-services.json的调试构建类型.我原来的字段有一个字段叫client_id,值是android:com.example.exampleapp,我刚刚删除了android:前缀并离开了com.example.exampleapp,之后我的gradle构建成功了.

希望能帮助到你!

编辑

我刚刚添加了android:我的前缀google-services.json,它继续正常工作.不知道究竟发生了什么,但我能够用上面提到的解决方案解决我的问题.


在gradle包装器中将版本从`2.8`更改为`2.10`,然后`File - :> Invalidate cache/Restart`

6> epool..:

用于修复:

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

您应该google-service.json从这里获得包的有效文件

用于修复:

请通过更新google-services插件的版本来修复版本冲突(有关最新版本的信息,请访问 https://bintray.com/android/android-tools/com.google.gms.google-services/)或将com.google.android.gms的版本更新为8.3.0:

您应该移动apply plugin: 'com.google.gms.google-services'到应用gradle.build文件的末尾.像这样的东西:

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



7> HenryChuang..:

我在使用Firebase时遇到了问题,我认为不同的包会导致问题.

我通过在Firebase控制台中添加新应用程序包解决了问题,然后再次下载google-services.json. 在此输入图像描述 在此输入图像描述 在此输入图像描述 在此输入图像描述



8> 小智..:

在android studio中打开google-services.json我们可以看到一个json对象,并在'client'jsonarray中包含以下项目

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

请验证您的包裹并继续.



9> Cole Murray..:

我发现使用此配置成功:

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'

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

使用8.40 Google Play服务.Alpha5和Alpha6给出了相同的2.8错误,无论distributionUrl是2.10



10> Chris..:

当我的软件包名称没有在我下载的google-services.json文件中显示时,就会发生这种情况.打开google-services.json文件,确保有一个client_info对象,其包名与您的清单包名对应.

在googleservices.json中:

"client": [
  {
    "client_info": {
    "mobilesdk_app_id": "my-app-id",
    "android_client_info": {
      "package_name": "com.me.android.test.myapp"
  }

在你的清单中:


您可能需要为项目重新创建一个新的google-services.json,您可以在此处创建:https://developers.google.com/mobile/add?platform = android&cntapi = gcm



11> lingyfh..:

您的google-services.json软件包名称必须与build.gradle applicationId(applicationId"您的软件包名称")匹配

推荐阅读
赛亚兔备_393
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有