[英]How to get flavor in buildType of build.gradle?
I have my gradle file as below, where I sign my app as Debug in debug build, and Release in release build.我有我的 gradle 文件,如下所示,我在调试版本中将我的应用程序签名为调试,并在发布版本中发布。 It has two flavor ie Develop and Production.
它有两种口味,即开发和生产。
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
productFlavors {
develop {
// Do something
}
production {
// Do something
}
}
However, I'm thinking of signing as Debug for Develop flavor (release) as well.但是,我也在考虑以 Debug for Develop 风格(发布)的身份签名。 How could I achieve that (ie access the flavor type variable in the buildType)?
我怎么能做到这一点(即访问 buildType 中的风味类型变量)?
As I understand your question you want something like this:据我了解你的问题,你想要这样的东西:
developDebug: signingConfigs.debug
productionDebug: signingConfigs.debug
developRelease: signingConfigs.debug
productionRelease: signingConfigs.release
You can achieve it this way:您可以通过以下方式实现:
android {
productFlavors {
develop {
// Do something
}
production {
// Do something
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
// Make an unfinished release build type
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
// Finish the release build type flavor specific
def runTasks = gradle.startParameter.taskNames.toString().toLowerCase()
if (runTasks.contains("develop")) {
release {
signingConfig signingConfigs.debug
}
} else if (runTasks.contains("production")) {
release {
signingConfig signingConfigs.release
}
}
}
}
Edit: I think this might be a cleaner solution编辑:我认为这可能是一个更清洁的解决方案
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
release-develop {
initWith buildTypes.release
signingConfig signingConfigs.debug
}
}
You could also use:您还可以使用:
productFlavors.develop.signingConfig signingConfigs.debug
inside of your release build type.在您的发布版本类型中。
Original Answer:原答案:
Something like this should do the trick.像这样的事情应该可以解决问题。
The hierarchy goes buildTypes -> defaultConfig -> productFlavors层次结构是 buildTypes -> defaultConfig -> productFlavors
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
defaultConfig {
signingConfig signingConfigs.release
}
productFlavors {
develop {
signingConfig signingConfigs.debug
// Do something
}
production {
// Do something
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.