尝试在我的项目中实施Firebase,但实施'com.google.firebase:firebase-core:16.0.1'下划线。拜托。
谢谢Mbuodile Obiosio,但不起作用,我不知道。
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.harun.basicmathquiz"
minSdkVersion 15
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 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
AND
// 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.1.2'
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 {
maven { url "https://maven.google.com" }
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的错误:所有gms / firebase库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本16.1.1、16.0.1、16.0.0、15.0.1。示例包括com.google.firebase:firebase-analytics-impl:16.1.1和com.google.firebase:firebase-analytics:16.0.1
答案 0 :(得分:2)
升级顶级gradle文件中的google-service插件,以避免混合版本错误:
classpath 'com.google.gms:google-services:4.0.1'
https://bintray.com/android/android-tools/com.google.gms.google-services/
答案 1 :(得分:2)
我也面临着同样的问题。我的问题通过这样做解决了 在Gradle中添加以下内容
classpath 'com.google.gms:google-services:4.0.1'
在依赖关系中
dependencies {
.
.
.
implementation ('com.google.firebase:firebase-database:16.0.1') {
exclude group: "com.google.android.gms"
}
}
apply plugin: 'com.google.gms.google-services'
答案 2 :(得分:1)
您正在混合版本,这就是为什么会出现错误。
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.harun.basicmathquiz"
minSdkVersion 15
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 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
不要忘记使用以下内容更新顶级build.gradle文件
classpath 'com.google.gms:google-services:4.0.1'