【发布时间】:2018-06-01 04:37:49
【问题描述】:
我正在尝试将 firebase 添加到我已经启动的项目中,但是在 build.gradle(应用程序)中,我在 play-services-maps 和 firebase 之间发生了依赖冲突,我到处查看并尝试更改版本号,但是还是行不通。 这是 build.gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.android.tencho.test"
minSdkVersion 22
targetSdkVersion 26
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:26.1.0'
implementation 'com.google.android.gms:play-services:15.0.1'
// implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.google.code.gson:gson:2.2.+'
compile 'com.google.firebase:firebase-core:16.0.0'
// //Firebase Auth
implementation 'com.google.firebase:firebase-auth:16.0.1'
// //FirebaseUI Auth
compile 'com.firebaseui:firebase-ui-auth:3.3.0'
}
apply plugin: 'com.google.gms.google-services'
Build.gradle(项目级别)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// The google-services plugin has 2 main functions:
// 1) Process the google-services.json file and produce Android resources that can be used in your
// application's code
// 2) Add dependencies for basic libraries required for the services you have enabled. This step requires
// that the apply plugin: 'com.google.gms.google-services' line be at the bottom of your app/build.gradle file
// so that no dependency collisions are introduced.
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
【问题讨论】:
-
错误是什么?
-
您应该为 firebase 和 google play 服务使用相同的版本。
-
所有 gms/firebase 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 16.0.1、16.0.0、15.0.4、15.0.1、12.0.1。示例包括 com.google.firebase:firebase-auth:16.0.1 和 com.google.firebase:firebase-analytics:16.0.0
标签: android firebase gradle google-play-services