安卓Gradle 3.0.0 - 为特定的flavors添加库依赖

3
我的应用包括一个库和3个口味:debug、release和custom。 我不想让我的应用在“custom”口味中包含该库。 在Gradle 3.0之前,我使用了以下代码:
releaseCompile project(path: ':myLib', configuration: "release")  
debugCompile project(path: ':..:myLib', configuration: "debug")  
// 'custom' ignored  

根据Google的指导将Gradle迁移至Android插件3.0,我需要在“custom”风格中使用implementation关键字和matchingFallbacks。我不想使用'matchingFallbacks',因为我不希望我的应用程序包含'custom'风格的lib。你有什么办法可以只在debug和release中编译lib吗?编辑也许可以添加if语句,例如:
if(flavor != custom){ 
    implementation project 'myLib' 
}
1个回答

4
我认为您可以通过类似以下代码的方式实现它:

我认为您可以通过类似以下代码的方式实现它:

dependencies {
   // use only mylib for debug and release
   releaseImplementation project(path: ':mylib')
   debugImplementation project(path: ':mylib')

   // this will be used by all the flavor
   implementation "com.android.support:appcompat-v7:27.0.2'
}

是的,那解决了我的问题。谢谢!我需要从'releaseImplementation'中删除'configuration:"release"'和'configuration:"debug"'。 - Jonny
太好了!很高兴能帮到你! - ישו אוהב אותך

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接