看到AS中External Libraries有好幾個同名但是版本不一樣的lib的時候咕幻,真的逼死強迫癥患者滤港。 這些多個重復(fù)的lib出現(xiàn)的原因就是多個module各自compile了同名但是不同版本的lib(即依賴沒有統(tǒng)一)搅方,所以統(tǒng)一性的確認這些依賴就好了栈拖。
<strong>Step1:</strong>
在根目錄新建一個config.gradle文件敦冬,里面鍵入要統(tǒng)一的依賴:
ext {
android = [
compileSdkVersion: 23,
buildToolsVersion: "23.0.3",
minSdkVersion : 15,
targetSdkVersion : 22,
versionCode : 1,
versionName : "1.0"
]
dependencies = [
"gson" : "com.google.code.gson:gson:2.6.2",
"eventbus" : 'org.greenrobot:eventbus:3.0.0',
"butterknife" : 'com.jakewharton:butterknife:7.0.1',
"support-design" : 'com.android.support:design:24.1.1',
"support-appcompatV7": 'com.android.support:appcompat-v7:24.1.1',
"support-percent" : 'com.android.support:percent:24.1.1',
"support-multidex" : 'com.android.support:multidex:1.0.1',
"glide" : 'com.github.bumptech.glide:glide:3.7.0',
"support-v4" : 'com.android.support:support-v4:24.1.1',
"okhttp3" : 'com.squareup.okhttp3:okhttp:3.3.1',
"nineoldandroids" : 'com.nineoldandroids:library:2.4.0'
]
}
<strong>Step2:</strong>
在根目錄的build.gradle文件里面頭部增加一句引用 apply from: "config.gradle"
<strong>Step3:</strong>
在module里面開始應(yīng)用:
compileSdkVersion rootProject.ext.android.compileSdkVersion //android{}節(jié)點
compile rootProject.ext.dependencies["support-appcompatV7"] //dependencies{}節(jié)點
<strong>The end</strong>
clean一下去External Libraries看看秸架,是不是還有重復(fù)的,如果還有救鲤,說明前面config里面的依賴其他地方還有遺漏的久窟,全局搜索一下在同樣方式替換一下就好了。
轉(zhuǎn)載:https://jackl-e-e.github.io/android/2016/08/26/多module統(tǒng)一gradle配置.html