如果引用的第三方库的支持库版本低于(或者不一致)app build.gradle中的支持库版本,可能会出现如下问题:
all com.android.support libraries must use the exact same version specification(mixing versions can lead to runtime crashes)
如下图所示:
去改第三方库所用的支持库版本比较麻烦,如果用的库很多的话工作量很大。这个时候我们可以考虑强制让所有模块都用相同的支持库版本。
在app build.gradle中添加:
configurations.all{
resolutionStrategy.eachDependency{ DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
}
}
}
其中,27.1.1就是你要使用的支持库版本号,你可以根据需要改成其它的。附上build.gradle 文件
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
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'
}
}
//强制让所有模块都用相同的支持库版本
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '27.1.1'
}
}
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
api 'com.android.support.test:runner:1.0.2'
api 'com.android.support.test.espresso:espresso-core:3.0.2'
api 'com.android.support.constraint:constraint-layout:1.1.3'
implementation project(':mavo-annotations')
//Android Support包
api 'com.android.support:design:27.1.1'
api 'com.android.support:appcompat-v7:27.1.1'
api 'com.android.support:support-v4:27.1.1'
//字体图标
api 'com.joanzapata.iconify:android-iconify-ionicons:2.2.2'
api 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2'
//fragmentation
api 'me.yokeyword:fragmentation:1.3.6'
api 'me.yokeyword:fragmentation-swipeback:1.3.6'
//Butter Knife
api 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//网络请求依赖
api 'com.squareup.okio:okio:1.13.0'
api 'com.squareup.okhttp3:okhttp:3.8.1'
api 'com.squareup.retrofit2:retrofit:2.3.0'
api 'com.squareup.retrofit2:converter-scalars:2.3.0'
//AVLoadingIndicatorView
api 'com.wang.avi:library:2.1.3'
//JSON依赖Android版
api 'com.alibaba:fastjson:1.1.57.android'
//banner依赖
api 'com.bigkoo:convenientbanner:2.0.5'
api 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32@aar'
//Log
api 'com.orhanobut:logger:2.1.1'
//数据库依赖
api 'org.greenrobot:greendao-generator:3.2.2'
api 'org.greenrobot:greendao:3.2.2'
}