Gradle:不止一个项目变体:myLib匹配使用者属性 [英] Gradle: More than one variant of project :myLib matches the consumer attributes

查看:1676
本文介绍了Gradle:不止一个项目变体:myLib匹配使用者属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写 myLib 的库使用 Firebase RemoteMessage 应用程序本身也使用 Firebase



使用gradle 4.7。



如何解决它?



project.gradle

  buildscript {

repositories {
google()
jcenter()
mavenCentral()
}
依赖关系{
classpath'com.android.tools.build:gradle:3.1.2'
classpath'com.google.gms:google-services: 3.3.0'
}
}

allprojects {
存储库{
google()
jcenter()
mavenCentral )
mavenLocal()
}
}

任务清理(类型:删除){
删除rootProject.buildDir
}

app.gradle

  apply plugin:'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
applicationIdcom.test.app
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName1.0
testInstrumentationRunnerandroid.support.test.runner.AndroidJUnitRunner
multiDexEnabled true
}

dexOptions {
preDexLibraries = false
jumboMode = false
javaMaxHeapSize2048M
}

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

依赖项{
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 '
实施on'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'

实施项目(:myLib)
}

应用插件:'com.google.gms.google-services'

myLib.gradle

  apply plugin:'com.android.library'

android {
compileSdkVersion 27


$ b defaultConfig {
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName1.0

testInstrumentationRunnerandroid.support.test.runner.AndroidJUnitRunner

}

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

}

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

实现'com.android.support:appcompat-v7:27.1.1'

实现组:'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 assembleDebug testApp \app> gradle clean assembleDebug


项目的多个变体:myLib匹配
消费者属性:


  • 配置':myLib:debugApiElements'变体android-aidl:


    • 找到artifactType'android-aidl',但不是必需的。

    • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容值'debug'。
    • li>
    • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的。
    • 必需的com.android.build.gradle。 internal.dependency.AndroidTypeAttr'Aar'和
      找到兼容值'Aar'。

    • 必需的org.gradle.usage'java-api'并找到兼容值'java-api '。


  • 配置':myLib:debugApiElements'变体android-classes:


    • 发现artifactType'android-classes',但没有
    • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容的值'debug'。

    • 找到com。 android.build.api.attributes.VariantAttr'debug'但不是必需的。

    • 需要com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和
      找到兼容值'Aar'。

    • 必需org.gradle.usage'java-api'并找到兼容值'java-api'。

    • 配置':myLib:debugApiElements'变体android-manifest:


      • 找到artifactType'android-manifest'但不是必需的。

      • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容值'debug'。

      • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的。

      • 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'一个nd
        找到兼容值'Aar'。

      • 必需org.gradle.usage'java-api'并找到兼容值'java-api'。



      • $配置':myLib:debugApiElements'变体android-renderscript:


        • 找到artifactType'
        • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容值'debug'。

        • 找到com.android.build.api.attributes.VariantAttr'debug'但不是必需的。
        • 必需的com.android.build.gradle.internal.dependency。 AndroidTypeAttr'Aar'和
          找到兼容值'Aar'。

        • 必需org.gradle.usage'java-api'并找到兼容值'java-api'。
        • li>

      • 配置':myLib:debugApiElements'变体jar:


        • artifactType'jar',但不是必需的。

        • 需要com.android.build.api.attributes.BuildTypeAttr'debug'并找到兼容的值'debug'。
        • 找到com.android.build.api.attributes。 VariantAttr'debug',但不是必需的。
        • 必需的com.android.build.gradle.internal.dependency.AndroidTypeAttr'Aar'和
          找到兼容值'Aar'。

        • 必需org.gradle.usage'java-api'并找到兼容值'java-api'。




解决方案

google-services Gradle插件可与Google Play服务和Firebase 15 + 配合使用,但您使用的版本<版本c $ c> 12.0.1

解决方案是:



编辑关于使用 google-services 3.3的一个已知问题在多模块应用程序中。这意味着降级到 google-services 3.2.1 可能是您唯一的选择,直到修复错误的新版本

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


A library that I wrote myLib uses RemoteMessage from Firebase, the app itself also uses Firebase.

Using gradle 4.7. Also facing this in 4.4.1.

How to fix it?

project.gradle

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

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

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'
}

Error output from testApp\myLib> gradle clean assembleDebug and testApp\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'.

解决方案

The google-services gradle plugin is made to work with Google Play Services and Firebase 15+, but you're using it with version 12.0.1.

The solution is to either:

  • Upgrade your Play Services and Firebase dependencies to version 15+ (note that they have different versions now)
  • Cancel your google-services upgrade to 3.3.0 until you upgrade to 15+, that is, downgrading the gradle plugin to version 3.2.1.

EDIT: There's a known issue about using google-services 3.3 in multimodule apps. That means downgrading to google-services to 3.2.1 may be your only option until a new version that fixes the bug is released.

BTW, you should move to FCM. GCM will stop working in a not too distant future.

这篇关于Gradle:不止一个项目变体:myLib匹配使用者属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆