首页 文章

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

提问于
浏览
122

我正在尝试按照Google给出的here示例将我的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无法识别我自己的应用程序包名称的任何想法?


EDIT:

好的,这次我得到了不同的错误 .

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

25 回答

  • 94

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

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

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

    enter image description here

  • 1

    Simpal an easy 在我的情况下,它解决了如下

    enter image description here

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

  • 0

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

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

    https://stackoverflow.com/a/34364376/570168

  • 161

    解决了获得异常的问题

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

    在FirebaseInstanceId.getInstance() . getToken()中

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

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

    exactly 匹配2) google-services.json

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

  • 3

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

    希望能帮助到你!

    EDIT

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

  • 5

    用于修复:

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

    您应该从here获取包的有效 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'
    
  • 10

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

    我通过在Firebase控制台中添加新应用程序包来解决,然后再次下载google-services.json .
    enter image description here

    enter image description here

    enter image description here

    enter image description here

  • 1

    我发现使用此配置成功:

    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

  • 3

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

    “client_id”:“android:你的包名”,“package_name”:“你的包名”,

    请验证您的包裹并继续 .

  • 1

    当我的软件包名称没有在我下载的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"
      }
    

    在你的清单中:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.me.android.test.myapp" >
    

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

  • 5

    如果在重命名应用程序包名称后发生这种情况,则需要更新以下内容:

    1) google-services.json 文件在您的应用程序中查找"package_name"属性的文件并使用新的包名更新它 .

    2)在 Google Developers Console 中更新您的应用程序客户端凭据,然后转到 Credentials 并选择您的Android客户端密钥,然后更新包名称以及新名称 .

    希望这会有所帮助 .

  • 5

    检查您的“google-services.json”文件中的package_name是否可用

  • 15

    我有同样的问题,只是轻松解决它确保manifest.xml文件中mainfest标签中的包的包名称和gradle app level文件中的application标签中的applicationId具有相同的包名称

    在manifest.xml中

    package="com.example.work"
    

    在gradle app级别

    applicationId "com.example.work"
    

    希望它有所帮助

  • 0

    我想因为你正在使用播放服务8.4.0

    它需要

    classpath 'com.android.tools.build:gradle:2.0.0-alpha5'
    classpath 'com.google.gms:google-services:2.0.0-alpha5'
    

    你也可以参考this .

  • 18

    对我来说,我必须检查 google-services.json 文件,并确保 "package_name" 已正确设置为我的Android应用程序的包名称 . 在我的情况下,自动生成的服务文件附加了 .backend .

  • 0

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

    确保项目 manifest 中的包名在 google-services.json 文件中完全相同

    谢谢 .

  • 1

    在项目gradle文件中添加它

    classpath 'com.google.gms:google-services:3.0.0'
    
  • 0

    只是Android工作室运行'以管理员身份运行'它将起作用

    或者在 google-services.json 文件上验证您的包名称

  • 1

    在上面研究清单文件中的包名称和gradle构建文件中的应用程序ID应该是相同的 . 我的问题没有解决 .

    实际上,gradle构建文件中的应用程序ID应与google-services.json文件中的程序包名称相同 . 如果您的google-services.json文件具有不同的包名称 . 从谷歌分析或firebase控制台删除该应用程序 . 并获得一个新文件 .

  • 3

    请验证 build.gradle.

    defaultConfig {
            applicationId "<packagename>"
            minSdkVersion 15
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
    

    验证包名称 . 它也可能导致错误 .

  • 20

    编写程序包名称时的两次:1 . 在Android Studio中创建新项目时2.在创建配置文件时

    你应该用小写字母写它 - 在改成小写后它起作用 . 如果你不想浪费时间,只需转到.json文件并用com.myname.myapplicationname替换com.myname.MyAPPlicationnamE(对于json文件中的每个匹配) .

  • 5

    如果你运行其他类型的构建(例如sign apk或其他),则必须选择构建的app类型然后运行项目 .

    请看下面的图片 . 要运行此项目,我们必须在运行配置弹出窗口中选择"app" .
    enter image description here

  • 0

    在我的情况下,我只需要这样做

    • 点击 Build

    • 点击 Make Project

    一切都好了 . 我仍然不知道发生了什么 .

  • 0

    1)检查google-services.json文件中的包名是否相同

    2)确保没有其他项目具有相同的包名称

    3)确保有互联网接入

    4)尝试同步项目并再次运行它

相关问题