我的gradle文件有错误。该应用程序可以正确编译,但是会生成运行时异常并立即崩溃。它显示:
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0, 27.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:exifinterface:27.1.0 less... (Ctrl+F1)
检查信息:
有一些库,工具和库的组合, 不兼容,或可能导致错误。一种这样的不兼容是 使用不支持的Android支持库版本进行编译 最新版本(或特别是低于您的版本 targetSdkVersion)。问题ID:GradleCompatible
我正在尝试从Firebase实时数据库中读取数据,并将其加载到具有cardview的recyclerview中。
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.pirewall"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.firebaseui:firebase-ui-database:4.3.1'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}
答案 0 :(得分:0)
在gradle文件中添加以下依赖项:
implementation 'com.android.support:exifinterface:28.0.0'
因此它可以与其他android支持库兼容。
答案 1 :(得分:0)
首先,请确保您使用的是最新版本的Firebase库。
假设您是,解决方案是为那些声明具有混合版本的库显式添加依赖项的最新版本。
如果您遵循Android Studio显示的提示:
Found versions 28.0.0, 27.1.0. Examples include com.android.support:animated-vector-drawable:28.0.0 and com.android.support:exifinterface:27.1.0
您需要添加
implementation “com.android.support:exifinterface:28.0.0”
(两个冲突版本的较高版本)添加到您的build.gradle
中。
在那之后,同步应重建依赖关系并解决错误。如果您在其他库中再次看到类似的错误,请继续执行相同的操作,直到所有此类错误消失为止。
添加这些依赖项而不必键入它的更简单方法是使用Android Studio键盘快捷键。
突出显示错误,然后按“ ALT + ENTER”,您将看到一个选项:
Add Library dependency > Edit Intention settings
这应该打开一个菜单,向您显示有问题的依赖性。在版本28.0.0
中添加该依赖项。同步,您应该会看到错误已解决。