【发布时间】:2015-03-24 03:24:18
【问题描述】:
我有几种构建类型: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")
注意:该库设置为编译所有变体。
有没有办法根据风格和构建类型指定条件项目依赖关系?
编辑:为避免混淆,请遵循我当前正在使用的项目中的相关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 {
// ...
}
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")
}
【问题讨论】:
-
它说什么错误?是
Could not find method pubReleaseCompile () for arguments xxx吗? -
Gradle DSL method not found: 'pubReleaseCompile()'. -
知道怎么做吗?
-
很遗憾,没有,但目前我只将它用于Hugo,所以它并不重要。如果你愿意,我会发布赏金。
-
我非常想要。