[英]Android Gradle ResolutionStrategy force stil downloads previous version of lib
[英]How to use Gradle resolutionStrategy to force dependency version?
我正在使用 Android 支持庫com.android.support:appcompat-v7:28.0.0
。 但是,我也在使用com.google.android.gms:play-services-nearby:16.0.0
,這取決於支持庫的早期版本。
為了解決這個問題,我使用了一個resolutionStrategy
來強制支持庫版本為 28.0.0,但它不起作用。 Android Studio 仍在抱怨依賴項沖突。 為什么我的解決策略不起作用?
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "rstudio.vedantroy.swarm"
minSdkVersion 21
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'
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:appcompat-v7:28.0.0'
}
}
dependencies {
//Developer-added dependencies
implementation 'com.google.android.gms:play-services-nearby:16.0.0'
implementation 'com.airbnb.android:mvrx:0.7.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
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'
}
您可以使用此配置將所有支持庫版本統一:
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "28.0.0"
}
}
}
此代碼段將查找具有組名稱com.android.support
每個依賴項,並強制將版本28.0.0
應用到內部依賴項。 這樣,您還可以指定項目范圍內的其他依賴項以使用顯式版本,例如 picasso 或 glide。 您只需要指定其組並在details.useVersion
指定其特定版本。
希望這可以幫助 :)
如果有人需要,Gradle Kotlin DSL 的腳本如下:
configurations.all {
resolutionStrategy {
eachDependency {
when (requested.module.toString()) {
"androidx.fragment:fragment" -> useVersion("1.3.0")
// ...etc
}
}
}
}
此外,您可能想查看官方文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.