gpt4 book ai didi

android - 在 android gradle 中循环依赖项时如何获得当前风格?

转载 作者:搜寻专家 更新时间:2023-11-01 09:40:43 24 4
gpt4 key购买 nike

我们有一个包含 100 多种口味的庞大项目。为了帮助我们的 Google Play 服务保持一致,我想定义一个默认版本,然后根据需要在 flavors 中覆盖它。

为了让我们所有的各种依赖项都使用相同的版本,我得到了这个:

 configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
//specifying a fixed version for all libraries with 'com.google.android.gms' group
if (details.requested.group == 'com.google.android.gms') {
details.useVersion '8.4.0'
}
}
}
}

我想定义:

defaultConfig {
ext.googlePlayServicesVersion '9.6.0'
}

然后按照我的口味过度驾驭它:

myFlavor {
// XXX plugin requires this older version
ext.googlePlayServicesVersion '8.4.0'
}

然后在configuration.all循环中使用变量version。

有没有办法在那个循环中访问那个变量?

最佳答案

您可以直接在您的 dependencies block 中执行此操作:

dependencies {
compile "com.google.android.gms:play-services-ads:$ext.googlePlayServicesVersion"
myFlavorCompile "com.google.android.gms:play-services-ads:$ext.googlePlayServicesVersionOld"
}

任何使用 flavorNameCompile 设置的项目 flavor 依赖项都将覆盖相同依赖项的默认 compile 依赖项,并允许您覆盖特定 flavor 的版本。

(我以play-services-ads为例)

关于android - 在 android gradle 中循环依赖项时如何获得当前风格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40031536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com