当我添加该行时:在build.gradle文件中编译'com.google.firebase:firebase-messaging:10.0.1'并立即在AndroidStudio中单击同步:
请通过更新版本来修复版本冲突 google-services插件(有关最新版本的信息是 可在 https://bintray.com/android/android-tools/com.google.gms.google-services/) 或将com.google.android.gms的版本更新为10.0.1。
我删除了行申请插件:'com.google.gms.google-services',然后错误消失。但firebase-auth失败:引起:java.lang.IllegalStateException:默认FirebaseApp未在此进程br.ufrn.imd.sgr中初始化。请务必先调用FirebaseApp.initializeApp(Context)。
请帮帮我。
的build.gradle(项目)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(模块应用):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "package.exemplo"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.google.firebase:firebase-auth:11.0.2'
compile 'com.google.code.gson:gson:2.6.2'
compile project (':volley')
}
apply plugin: 'com.google.gms.google-services'
答案 0 :(得分:0)
这里的交易:你添加了太旧的依赖。
您的Firebase Auth依赖项版本为11.0.2
:
compile 'com.google.firebase:firebase-auth:11.0.2'
您在版本10.0.1
中添加了一个Firebase依赖项:
compile 'com.google.firebase:firebase-messaging:10.0.1'
因此存在依赖版本冲突。这就是您尝试同步时出现Gradle构建错误的原因。
要解决此问题,只需将您的firebase-messaging
依赖版本设为最新版本,然后重新应用Google Services Gradle插件:
dependencies {
...
compile 'com.google.firebase:firebase-auth:11.0.2'
compile 'com.google.firebase:firebase-messaging:11.0.2'
...
}
apply plugin: 'com.google.gms.google-services'
希望这有帮助。