解決AndroidStudio Gradle方式引用第三方庫重複依賴的問題
阿新 • • 發佈:2018-12-13
在一些使用依賴比較多的專案可能出現這個問題。
比如sample中使用了下面的依賴
implementation 'com.android.support:appcompat-v7:25.0.0'
implementation 'com.allenliu.versionchecklib:library:2.0.5'
而第三方庫中,同樣存在相同的依賴,但是版本不同,那麼就可能出現上述問題。
compile 'com.android.support:appcompat-v7:27.0.0'
遇到這個問題,可以先去檢視第三方庫的原始碼,檢視library中的build.gradle檔案內是否存在相同的庫。
如果有
在sample新增依賴的時候,排除第三方庫中的重複依賴。
implementation ('com.allenliu.versionchecklib:library:2.0.5') {
exclude group: 'com.android.support', module: 'appcompat-v7'
}
同樣如果有其它,比如 appcompat-v、support-v4 、v7等多個依賴衝突
則依次追加
implementation ('com.allenliu.versionchecklib:library:2.0.5') {
exclude group : 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-v7'
}