android - Gradle:项目的多个变体 :myLib 匹配消费者属性
问题描述
我编写的一个库myLib
使用RemoteMessage
来自Firebase
,应用程序本身也使用Firebase
.
使用 gradle 4.7。在 4.4.1 中也面临这个问题。
如何解决?
项目.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
}
应用程序.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'
}
testApp\myLib> gradle clean assembleDebug
和的错误输出testApp\app> gradle clean assembleDebug
project :myLib 的多个变体与消费者属性匹配:
- 配置 ':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'。
- 配置 ':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' 并找到兼容值 'Aar'。
- 需要 org.gradle.usage 'java-api' 并找到兼容值 'java-api'。
- 配置 ':myLib:debugApiElements' 变体 android-renderscript:
- 找到 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'。
- 配置 ':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'。
解决方案
gradlegoogle-services
插件可与 Google Play Services 和 Firebase15+
一起使用,但您将其与 version 一起使用12.0.1
。
解决方案是:
- 将您的 Play 服务和 Firebase 依赖项升级到版本
15+
(请注意,它们现在有不同的版本) - 取消
google-services
升级到3.3.0
直到升级到15+
,即将 gradle 插件降级到 version3.2.1
。
编辑 1:在多模块应用程序中使用存在一个已知问题google-services
3.3
。这意味着降级到google-services
to3.2.1
可能是您唯一的选择,直到发布修复该错误的新版本。
编辑 2:上述错误已在gradle 插件版本4.0.1
中修复!google-services
(并且该版本4.0.2
还修复了在某些情况下发生的 NPE)
顺便说一句,您应该转到 FCM。 GCM 将在不久的将来停止工作。
推荐阅读
- python - 从numpy中的张量中过滤出零矩阵
- mysql - 使用 mysql 和 apache 的目录中的身份验证不起作用
- python - 我的 N-Queens 解决方案有什么问题?
- postgresql - 与 postgreSQL 模式连接
- java - 如何创建一个从 0 到 Long 范围的大循环?
- react-native - OnEndReached 由于数据少于一页而连续触发
- python - Django rest 框架 ApiView reurn 可执行文件
- javascript - 警告:道具类型失败:提供给视图的道具“背景颜色”无效:
- javascript - 将文件复制到新位置
- sql - 插入多行 Qt Quick Local Storage?