关于android:Gradle:不止一个项目变体:myLib与使用者属性匹配

Gradle: More than one variant of project :myLib matches the consumer attributes

我写的myLib库使用Firebase中的RemoteMessage,应用本身也使用Firebase

使用gradle 4.7。在4.4.1。

中也面临此问题。

如何修复?

project.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
buildscript {
   
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        mavenLocal()
    }
}

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

app.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId"com.test.app"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName"1.0"
        testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    dexOptions {
        preDexLibraries = false
        jumboMode = false
        javaMaxHeapSize"2048M"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:27.1.1'

    implementation 'com.google.android.gms:play-services-gcm:12.0.1'
    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.google.firebase:firebase-core:12.0.1'
    implementation 'com.google.firebase:firebase-messaging:12.0.1'
    implementation 'com.google.firebase:firebase-crash:12.0.1'

    implementation project(":myLib")
}

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

myLib.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
apply plugin: 'com.android.library'

android {
    compileSdkVersion 27



    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName"1.0"

        testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"

    }

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

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:27.1.1'

    implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
    implementation 'com.j256.ormlite:ormlite-core:5.0'
    implementation 'com.j256.ormlite:ormlite-android:5.0'

    implementation 'com.google.firebase:firebase-messaging:12.0.1'
}

testApp\\myLib> gradle clean assembleDebugtestApp\\app> gradle clean assembleDebug

的错误输出

More than one variant of project :myLib matches the
consumer attributes:

  • Configuration ':myLib:debugApiElements' variant android-aidl:

    • Found artifactType 'android-aidl' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
      found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant android-classes:

    • Found artifactType 'android-classes' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
      found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant android-manifest:

    • Found artifactType 'android-manifest' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
      found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant android-renderscript:

    • Found artifactType 'android-renderscript' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
      found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  • Configuration ':myLib:debugApiElements' variant jar:

    • Found artifactType 'jar' but wasn't required.
    • Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
    • Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
    • Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and
      found compatible value 'Aar'.
    • Required org.gradle.usage 'java-api' and found compatible value 'java-api'.


google-services gradle插件可与Google Play服务和Firebase 15+一起使用,但是您将其与版本12.0.1一起使用。

解决方案是:

  • 将您的Play服务和Firebase依赖项升级到版本15+(请注意,它们现在具有不同的版本)
  • 取消升级到3.3.0的操作,直到升级到3.3.0
    15+,即将gradle插件降级到版本3.2.1

编辑1:有关在多模块应用程序中使用google-services 3.3的已知问题。这意味着降级到google-services3.2.1可能是您唯一的选择,直到发布修复该错误的新版本为止。

编辑2:上述错误已在google-services gradle插件的4.0.1版本中修复! (并且版本4.0.2也修复了在某些情况下发生的NPE)

顺便说一句,您应该转到FCM。
GCM将在不久的将来停止工作。


当我使用google-services:3.3.0时出现此错误。

在项目.gradle中降级到classpath 'com.google.gms:google-services:3.2.1'

应该可以解决问题。

更新:在当前版本中可能不应该出现。


升级到3.3.1时遇到类似问题

通过降级到3.2.1修复了该问题

我们可以将Firebase版本> = 15与3.2.1一起使用


以下步骤对我有用---

  • 转到android / build.gradle文件。
  • 搜索jcentre()方法。
  • 将所有jcenter()方法移至其块内的底部。

  • 过去几天我也遇到了类似的问题。

    1
    2
    implementation 'com.google.android.gms:play-services-auth:15.0.0'
    implementation 'com.google.firebase:firebase-messaging:15.0.0'

    解决方案是降级到

    1
    2
    implementation 'com.google.android.gms:play-services-auth:12.0.1'
    implementation 'com.google.firebase:firebase-messaging:12.0.1'

    或考虑离开Goog??le Cloud Services并完全升级到FCM

    请注意,它们具有不同的版本号,您可以在此处查找