Gradle:项目的多个变体 :myLib 匹配消费者属性 [英] Gradle: More than one variant of project :myLib matches the consumer attributes

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

问题描述

我编写的一个库 myLib 使用来自 FirebaseRemoteMessage,应用本身也使用 Firebase.

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

使用 gradle 4.7.在 4.4.1 中也面临这个.

Using gradle 4.7. Also facing this in 4.4.1.

如何解决?

project.gradle

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

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

来自 testApp\myLib> 的错误输出gradle clean assembleDebugtestApp\app>gradle clean assembleDebug

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

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

  • 配置 ':myLib:debugApiElements' 变体 android-aidl:
    • 找到了 artifactType 'android-aidl' 但不是必需的.
    • 需要 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'.
    • 找到 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'.
    • 找到 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' 和找到兼容值Aar".
    • 需要 org.gradle.usage 'java-api' 并找到兼容值 'java-api'.
    • 找到 artifactType 'android-renderscript' 但不是必需的.
    • 需要 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'.
    • 找到 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+ 配合使用,但您使用的是 12.0.1 版本.

    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.

    解决方案是:

    • 将您的 Play 服务和 Firebase 依赖项升级到版本 15+ (注意他们现在有不同的版本)
    • 取消您的 google-services 升级到 3.3.0,直到您升级到15+,即把gradle插件降级到3.2.1版本.
    • 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.

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

    EDIT 1: 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.

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

    EDIT 2: The bug mentioned above has been fixed in the version 4.0.1 of the google-services gradle plugin! (and the version 4.0.2 also fixes an NPE that occurred in some cases)

    顺便说一句,你应该转向 FCM.GCM 将在不久后停止工作未来.

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

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