在Android Studio中创建新项目后,我按照manual中的说明向该项目添加了Firebase和Firebase消息。
但是,在Gradle同步后,IDE显示错误:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0-beta01, 26.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0-beta01 and com.android.support:support-media-compat:26.1.0
没有Firebase库,则项目构建正确。
项目级build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
模块级build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ru.sabernyan.myapplication"
minSdkVersion 16
targetSdkVersion 28
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 "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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:28.0.0-beta01'
}
apply plugin: 'com.google.gms.google-services'
其余文件未更改。
版本:
Android Studio 3.1.3
Build #AI-173.4819257, built on June 4, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.17.11-zen1
答案 0 :(得分:9)
使用gradle app:dependencies
,我得到了一个依赖项列表:
debugCompileClasspath - Resolved configuration for compilation for variant: debug
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.30
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.30
| \--- org.jetbrains:annotations:13.0
+--- com.google.firebase:firebase-core:16.0.1
| +--- com.google.firebase:firebase-analytics:16.0.1
| | +--- com.google.android.gms:play-services-basement:15.0.1
| | | \--- com.android.support:support-v4:26.1.0
| | | +--- com.android.support:support-compat:26.1.0 -> 28.0.0-beta01
| | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | +--- com.android.support:collections:28.0.0-beta01
| | | | | \--- com.android.support:support-annotations:28.0.0-beta01
| | | | +--- android.arch.lifecycle:runtime:1.1.1
| | | | | +--- android.arch.lifecycle:common:1.1.1
| | | | | | \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
| | | | | +--- android.arch.core:common:1.1.1
| | | | | | \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
| | | | | \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
| | | | \--- com.android.support:versionedparcelable:28.0.0-beta01
| | | | \--- com.android.support:support-annotations:28.0.0-beta01
| | | +--- com.android.support:support-media-compat:26.1.0 -> 28.0.0-beta01
| | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | \--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | +--- com.android.support:support-core-utils:26.1.0 -> 28.0.0-beta01
| | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | +--- com.android.support:documentfile:28.0.0-beta01
| | | | | \--- com.android.support:support-annotations:28.0.0-beta01
| | | | +--- com.android.support:loader:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | | +--- android.arch.lifecycle:livedata-core:1.1.1
| | | | | | +--- android.arch.lifecycle:common:1.1.1 (*)
| | | | | | +--- android.arch.core:common:1.1.1 (*)
| | | | | | \--- android.arch.core:runtime:1.1.1
| | | | | | +--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
| | | | | | \--- android.arch.core:common:1.1.1 (*)
| | | | | \--- android.arch.lifecycle:viewmodel:1.1.1
| | | | | \--- com.android.support:support-annotations:26.1.0 -> 28.0.0-beta01
| | | | +--- com.android.support:localbroadcastmanager:28.0.0-beta01
| | | | | \--- com.android.support:support-annotations:28.0.0-beta01
| | | | \--- com.android.support:print:28.0.0-beta01
| | | | \--- com.android.support:support-annotations:28.0.0-beta01
| | | +--- com.android.support:support-core-ui:26.1.0 -> 28.0.0-beta01
| | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | +--- com.android.support:support-core-utils:28.0.0-beta01 (*)
| | | | +--- com.android.support:customview:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | \--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | +--- com.android.support:viewpager:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | | \--- com.android.support:customview:28.0.0-beta01 (*)
| | | | +--- com.android.support:coordinatorlayout:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | | \--- com.android.support:customview:28.0.0-beta01 (*)
| | | | +--- com.android.support:drawerlayout:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | | \--- com.android.support:customview:28.0.0-beta01 (*)
| | | | +--- com.android.support:slidingpanelayout:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | | \--- com.android.support:customview:28.0.0-beta01 (*)
| | | | +--- com.android.support:interpolator:28.0.0-beta01
| | | | | \--- com.android.support:support-annotations:28.0.0-beta01
| | | | +--- com.android.support:swiperefreshlayout:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | | \--- com.android.support:interpolator:28.0.0-beta01 (*)
| | | | +--- com.android.support:asynclayoutinflater:28.0.0-beta01
| | | | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | | | \--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | | \--- com.android.support:cursoradapter:28.0.0-beta01
| | | | \--- com.android.support:support-annotations:28.0.0-beta01
| | | \--- com.android.support:support-fragment:26.1.0 -> 28.0.0-beta01
| | | +--- com.android.support:support-compat:28.0.0-beta01 (*)
| | | +--- com.android.support:support-core-ui:28.0.0-beta01 (*)
| | | +--- com.android.support:support-core-utils:28.0.0-beta01 (*)
| | | +--- com.android.support:support-annotations:28.0.0-beta01
| | | +--- com.android.support:loader:28.0.0-beta01 (*)
| | | \--- android.arch.lifecycle:viewmodel:1.1.1 (*)
| | +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
| | +--- com.google.android.gms:play-services-stats:15.0.1
| | | \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
| | +--- com.google.firebase:firebase-analytics-impl:[16.1.1] -> 16.1.1
| | | +--- com.google.android.gms:play-services-ads-identifier:15.0.1
| | | | \--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1 (*)
| | | +--- com.google.android.gms:play-services-basement:15.0.1 (*)
| | | +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
| | | +--- com.google.android.gms:play-services-stats:15.0.1 (*)
| | | +--- com.google.android.gms:play-services-tasks:15.0.1
| | | | \--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
| | | +--- com.google.firebase:firebase-common:16.0.0
| | | | +--- com.google.android.gms:play-services-basement:15.0.1 (*)
| | | | \--- com.google.android.gms:play-services-tasks:15.0.1 (*)
| | | \--- com.google.firebase:firebase-iid:16.0.0 -> 16.2.0
| | | +--- com.google.android.gms:play-services-basement:15.0.1 (*)
| | | +--- com.google.android.gms:play-services-stats:15.0.1 (*)
| | | +--- com.google.android.gms:play-services-tasks:15.0.1 (*)
| | | +--- com.google.firebase:firebase-common:16.0.0 (*)
| | | \--- com.google.firebase:firebase-iid-interop:16.0.0
| | | +--- com.google.android.gms:play-services-base:15.0.1
| | | | +--- com.google.android.gms:play-services-basement:[15.0.1] -> 15.0.1 (*)
| | | | \--- com.google.android.gms:play-services-tasks:[15.0.1] -> 15.0.1 (*)
| | | \--- com.google.android.gms:play-services-basement:15.0.1 (*)
| | \--- com.google.firebase:firebase-common:16.0.0 (*)
| \--- com.google.firebase:firebase-measurement-connector-impl:16.0.1
| +--- com.google.android.gms:play-services-basement:15.0.1 (*)
| +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
| +--- com.google.firebase:firebase-analytics:[16.0.1] -> 16.0.1 (*)
| +--- com.google.firebase:firebase-analytics-impl:[16.1.1] -> 16.1.1 (*)
| +--- com.google.firebase:firebase-common:16.0.0 (*)
| \--- com.google.firebase:firebase-measurement-connector:16.0.0
| \--- com.google.android.gms:play-services-basement:15.0.1 (*)
+--- com.google.firebase:firebase-messaging:17.1.0
| +--- com.google.android.gms:play-services-basement:15.0.1 (*)
| +--- com.google.android.gms:play-services-tasks:15.0.1 (*)
| +--- com.google.firebase:firebase-common:16.0.0 (*)
| +--- com.google.firebase:firebase-iid:[16.2.0] -> 16.2.0 (*)
| \--- com.google.firebase:firebase-measurement-connector:16.0.0 (*)
+--- com.android.support:appcompat-v7:28.0.0-beta01
| +--- com.android.support:support-annotations:28.0.0-beta01
| +--- com.android.support:support-compat:28.0.0-beta01 (*)
| +--- com.android.support:collections:28.0.0-beta01 (*)
| +--- com.android.support:cursoradapter:28.0.0-beta01 (*)
| +--- com.android.support:support-core-utils:28.0.0-beta01 (*)
| +--- com.android.support:support-fragment:28.0.0-beta01 (*)
| +--- com.android.support:support-vector-drawable:28.0.0-beta01
| | +--- com.android.support:support-annotations:28.0.0-beta01
| | \--- com.android.support:support-compat:28.0.0-beta01 (*)
| \--- com.android.support:animated-vector-drawable:28.0.0-beta01
| +--- com.android.support:support-vector-drawable:28.0.0-beta01 (*)
| \--- com.android.support:support-core-ui:28.0.0-beta01 (*)
+--- com.android.support:support-media-compat:28.0.0-beta01 (*)
+--- com.android.support.constraint:constraint-layout:1.1.2
| \--- com.android.support.constraint:constraint-layout-solver:1.1.2
\--- com.android.support:design:28.0.0-beta01
+--- com.android.support:support-annotations:28.0.0-beta01
+--- com.android.support:support-compat:28.0.0-beta01 (*)
+--- com.android.support:support-core-ui:28.0.0-beta01 (*)
+--- com.android.support:support-core-utils:28.0.0-beta01 (*)
+--- com.android.support:support-fragment:28.0.0-beta01 (*)
+--- com.android.support:transition:28.0.0-beta01
| +--- com.android.support:support-annotations:28.0.0-beta01
| \--- com.android.support:support-compat:28.0.0-beta01 (*)
+--- com.android.support:appcompat-v7:28.0.0-beta01 (*)
+--- com.android.support:cardview-v7:28.0.0-beta01
| \--- com.android.support:support-annotations:28.0.0-beta01
\--- com.android.support:recyclerview-v7:28.0.0-beta01
+--- com.android.support:support-annotations:28.0.0-beta01
+--- com.android.support:support-compat:28.0.0-beta01 (*)
\--- com.android.support:support-core-ui:28.0.0-beta01 (*)
它表明Firebase提取了依赖项com.android.support:support-v4:26.1.0
,所以我覆盖了它,现在我的build.gradle看起来像这样:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ru.sabernyan.myapplication"
minSdkVersion 16
targetSdkVersion 28
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 "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support:support-v4:28.0.0-beta01' // <= dependency overwritten
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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:28.0.0-beta01'
}
apply plugin: 'com.google.gms.google-services'
而且有效!
答案 1 :(得分:1)
添加错误消息中列出的所有库都将摆脱该消息。 (添加每个库后,您必须再次检查错误消息)。对我来说,我必须添加两个库:
dependencies {
...
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0' // <-- added
implementation 'com.android.support:support-media-compat:28.0.0' // <-- added
...
}
不过,我仍然想知道,为什么Firebase使用这些旧库,以及如果Firebase实际上需要这些旧库,为什么这样的简单修补程序可以工作。
答案 2 :(得分:0)
将此添加到依赖项中
implementation 'com.android.support:design:28.0.0'
implementation "com.android.support:customtabs:28.0.0"
implementation 'com.android.support:mediarouter-v7:28.0.0'
答案 3 :(得分:-1)
我添加这2行并解决了我的问题:
实现'com.android.support:support-media-compat:28.0.0-beta01'
实现'com.android.support:support-v4:28.0.0-beta01'