找不到软件包名称“....”的匹配客户端具有不同的构建变量

2022-09-01 21:30:55

我想要实现推送通知。我添加到项目级别:

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.google.gms:google-services:3.0.0'
}

并转到应用级别:(在文件底部)

   ....
   compile 'com.squareup.okhttp3:okhttp:3.3.0'
}
apply plugin: 'com.google.gms.google-services'

然后,我将google-services.json文件添加到应用程序级别的项目中

但是,当我同步gradle时,它会启动错误:

No matching client found for package name "...." 

在 gradle 中,我有 2 种不同的构建变体,看起来像这样:

enter image description here

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="es.xxx.awsomeapp">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:name=".realm.XXXXXX"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher_chv"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity

最后是等级:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
    maven { url "https://jitpack.io" }
    maven { url 'http://dl.bintray.com/amulyakhare/maven' }
    mavenCentral()
}
android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    productFlavors {
        vanilla {
            applicationId "es.xxx.awsomeApp"
            resValue 'string', 'app_name', "Awsome"
        }
        chv {
            applicationId "es.xxx.awsomeApp.chv"
            resValue 'string', 'app_name', "Awsome CHV"
            signingConfig signingConfigs.chv_release
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //Auxiliar libraries
    compile 'org.igniterealtime.smack:smack-android-extensions:4.2.0-beta2'
    //Auxiliar libraries
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'org.igniterealtime.smack:smack-android-extensions:4.2.0-beta2'
    compile 'org.igniterealtime.smack:smack-tcp:4.2.0-beta2'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta2'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.orhanobut:logger:1.15'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'com.github.Slyce-Inc:SlyceMessaging:1.1.2'
    compile 'io.realm:android-adapters:1.4.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.android.support:cardview-v7:24.2.1'
    compile 'com.rengwuxian.materialedittext:library:1.8.3'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.squareup.okhttp3:okhttp:3.3.0'
    compile 'com.google.firebase:firebase-messaging:9.8.0'
    testCompile 'junit:junit:4.12'
    testCompile 'org.robolectric:robolectric:3.0'
    testCompile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'org.igniterealtime.smack:smack-tcp:4.2.0-beta2'
    testCompile 'com.android.support.constraint:constraint-layout:1.0.0-beta2'
    testCompile 'com.android.support:design:24.2.1'
    testCompile 'com.orhanobut:logger:1.15'
    testCompile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    testCompile 'com.github.Slyce-Inc:SlyceMessaging:1.1.2'
}
apply plugin: 'com.google.gms.google-services'

还有火基控制台。

enter image description here

我该如何解决?

请注意,json 文件是其项目中的每一个。


答案 1
  1. 只需转到google-services.json
  2. 将包名称更改为包的名称
{
  "client_info": {
    "mobilesdk_app_id": "1:113908578702:android:a0a98decfd9f22466f4cdf",
    "android_client_info": {
      "package_name": "com.example.Appname"
    }
  }
}
  1. 同步您的项目,它将得到解决

答案 2

我遇到了同样的错误。我正在使用多种口味。因此,我把 in 目录。google-services.jsonapp/src/{flv}

它对一种口味效果很好,但对其他口味不起作用。问题是,我还在应用程序目录中放置了相应的风格。google-services.json

Google只有在应用程序目录中没有找到google-services.json时才会搜索子目录/风味目录。

因此,请确保不要放入应用程序目录,以防万一您对多种口味有单独的定义。google-services.jsongoogle-services.json

有关 Android 产品变种的模式详细信息,请参阅此文章