Ken*_*Ken 5 android build gradle
场景:我们有一个Android应用程序,其中包含一些不同的可选组件,我们希望能够根据客户需求和许可来包含/排除这些组件.是否可以基于构建参数包含特定项目,而不创建所有排列作为构建风格?
./gradlew assembleRelease -PincludeFeatureA=true -PincludeFeatureB=false
Run Code Online (Sandbox Code Playgroud)
我以为我可以在依赖项中做这样的事情:
dependencies {
if(includeFeatureA){
compile project(':featureAEnabled')
} else {
compile project(':featureADisabled')
}
}
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.
更新:考虑到可切换功能的数量,对每个排列使用显式构建变体是很麻烦的.
例如,给定3个可切换功能,我不想构建这样的风格:
Feature1
Feature1-Feature2
Feature1-Feature3
Feature1-Feature2-Feature3
Feature2
Feature2-Feature3
...
Run Code Online (Sandbox Code Playgroud)
我的方案的解决方案是将if语句移出依赖项:
假设命令行:
gradlew assembleRelease -PincludeFeatureA
Run Code Online (Sandbox Code Playgroud)
在项目build.gradle的开头,我包括:
def featureA_Proj=':featureA_NotIncluded'
Run Code Online (Sandbox Code Playgroud)
然后我有这样的任务:
task customizeFeatureA(){
if(project.hasProperty('includeFeatureA')){
println 'Including Feature A'
featureA_Proj=':featureA'
}
}
Run Code Online (Sandbox Code Playgroud)
最后,在依赖项下,我只包括:
dependencies{
include(featureA_Proj)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3656 次 |
| 最近记录: |