我有几种构建类型:debug
, release
. 我也有两种口味pub
和dev
.
pub
调味的应用程序取决于pub
库,类似的dev
味道.现在,我希望debug
构建类型应用程序依赖于debug
库的构建.以下不起作用:
pubReleaseCompile project(path: ':common', configuration: "pubRelease")
devReleaseCompile project(path: ':common', configuration: "devRelease")
pubDebugCompile project(path: ':common', configuration: "pubDebug")
devDebugCompile project(path: ':common', configuration: "devDebug")
Run Code Online (Sandbox Code Playgroud)
注意:库已设置为编译所有变体.
有没有办法根据flavor和build类型指定条件项目依赖?
编辑:为避免混淆,请遵循build.gradle
我目前正在使用的项目中的相关文件.
project/common/build.gradle(库)
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.hugo' // annotation-based code generated logs only in debug build
android {
defaultPublishConfig "pubRelease"
publishNonDefault true // four variants of the library are built
buildTypes {
debug {}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
pub {
// custom build config fields
}
dev {
// custom build config fields
}
}
}
dependencies {
// ...
}
Run Code Online (Sandbox Code Playgroud)
project/parent/build.gradle(使用该库的应用程序模块之一)
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
android {
// ...
signingConfigs {
release {
// ...
}
}
buildTypes {
release {
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
shrinkResources true
minifyEnabled true
}
debug {
versionNameSuffix '-debug'
}
}
productFlavors {
pub {
// custom res values
}
dev {
// custom res values
}
}
}
dependencies {
// ...
pubCompile project(path: ':common', configuration: "pubRelease")
devCompile project(path: ':common', configuration: "devRelease")
}
Run Code Online (Sandbox Code Playgroud)
Eug*_*nec 47
构建插件3.0.0使用变体感知依赖项解析,因此devDebug
应用程序模块的devDebug
变体将自动使用其库模块依赖项的变体.要回答这个问题,这就足够了:
implementation project(':common')
Run Code Online (Sandbox Code Playgroud)
在这里阅读更多内容:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#variant_aware
我能在这里找到解决方案:https://github.com/JakeWharton/u2020/blob/master/build.gradle
有关原始代码不足的原因,请访问:https://code.google.com/p/android/issues/detail?id = 162285
工作方案:
configurations {
pubDebugCompile
devDebugCompile
pubReleaseCompile
devReleaseCompile
}
dependencies {
pubReleaseCompile project(path: ':common', configuration: "pubRelease")
devReleaseCompile project(path: ':common', configuration: "devRelease")
pubDebugCompile project(path: ':common', configuration: "pubDebug")
devDebugCompile project(path: ':common', configuration: "devDebug")
}
Run Code Online (Sandbox Code Playgroud)
首先定义各种构建类型:
buildTypes {
pubRelease {
//config
}
devRelease {
//config
}
}
Run Code Online (Sandbox Code Playgroud)
创建仅针对特定buildType和flavor执行的任务:
task pubReleaseTask << {
//code
}
task devReleaseTask << {
//code
}
Run Code Online (Sandbox Code Playgroud)
您可以动态添加依赖项:
tasks.whenTaskAdded { task ->
if (task.name == 'pubRelease') {
task.dependsOn pubReleaseTask
}
if (task.name == 'devRelease') {
task.dependsOn devReleaseTask
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
30442 次 |
最近记录: |