我写的myLib
库使用RemoteMessage
中的Firebase
,应用程序本身也使用Firebase
。
使用gradle 4.7。也见于4.4.1。
如何解决?
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'
}
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'。
- 发现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'。
答案 0 :(得分:86)
google-services
gradle插件适用于Google Play服务和Firebase 15+
,但您使用的是版本12.0.1
。
解决方案是:
15+
(note that they have different versions now) google-services
升级至3.3.0
,直至升级为
15+
,即将gradle插件降级为版本3.2.1
。 编辑1 :有a known issue about using google-services
3.3
in multimodule apps。这意味着在修复错误的新版本发布之前,降级到google-services
到3.2.1
可能是您唯一的选择。
编辑2 :上述错误已在4.0.1
gradle插件的版本google-services
中得到修复! (版本4.0.2
也修复了在某些情况下发生的NPE)
BTW,你应该转向FCM。 GCM will stop working in a not too distant future.
答案 1 :(得分:28)
使用google-services时出现此错误:3.3.0。
在项目中降级为classpath 'com.google.gms:google-services:3.2.1'
.gradle。
应该解决这个问题。
更新:当前版本可能不会出现。
答案 2 :(得分:7)
升级到3.3.1时面临类似问题
通过降级到3.2.1
来修复它我们可以使用firebase版本> = 15和3.2.1
答案 3 :(得分:1)
以下步骤对我有用---
jcentre()
方法。 jcenter()
方法移至其块内的底部。 答案 4 :(得分:0)
过去几天我遇到了类似的问题。
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.google.firebase:firebase-messaging:15.0.0'
解决方案要么降级到
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
或考虑完全退出Google云服务并升级到FCM
请注意,它们具有不同的版本号,您可以查找here