我有两种口味,比如香草和巧克力.我也有Debug和Release构建类型,我需要Vanilla Release才能有一个字段为true,而其他3个组合应该是false.
def BOOLEAN = "boolean"
def VARIABLE = "VARIABLE"
def TRUE = "true"
def FALSE = "false"
VANILLA {
debug {
buildConfigField BOOLEAN, VARIABLE, FALSE
}
release {
buildConfigField BOOLEAN, VARIABLE, TRUE
}
}
CHOCOLATE {
buildConfigField BOOLEAN, VARIABLE, FALSE
}
Run Code Online (Sandbox Code Playgroud)
我有一个错误,所以我猜调试和发布技巧不起作用.有可能这样做吗?
我的Android应用程序有很多种,我希望除了一个以外的所有应用程序都使用相同的密钥.有一个需要使用不同的密钥.
如何覆盖signingConfig
应用程序的1种风格(但在相同的构建类型中,例如"发布")?
gradlew assembleRelease
命令运行所有发布版本最后一点非常重要,因为我目前有超过120种不同的口味和成长.为了单独定制每一种风味,需要做很多额外的工作.
相关帖子我试过:
signingConfig
反正buildTypes
内部,productFlavors
但我不明白如何做到这一点.总的来说,每个解决方案似乎仍然使用默认的发布配置,而不是我的自定义配置.
我的重要部分build.gradle
看起来像这样:
signingConfigs {
releaseConfig {
storeFile file('key')
storePassword "pass"
keyAlias "alias"
keyPassword "pass"
}
custom {
storeFile file('custom_key')
storePassword "pass"
keyAlias "alias"
keyPassword "pass"
}
}
productFlavors {
apple {
applicationId "demo.apple"
}
banana {
applicationId "demo.banana"
}
// …
Run Code Online (Sandbox Code Playgroud) 我在同一个 Android Studio 项目中有两个不同的应用程序。我有两种口味“flavor1”和“flavor2”,具有三种不同的构建类型“staging”、“debug”和“release”
问题是我需要为每个应用程序使用不同的密钥存储。
现在我有了这个,但它只能使用相同的密钥存储进行签名。
signingConfigs {
release {
def Properties props = new Properties()
def propFile = new File('./signing.properties')
if (propFile.canRead()) {
props.load(new FileInputStream(propFile))
if (props != null && props.containsKey('STORE_FILE')
&& props.containsKey('STORE_PASSWORD')
&& props.containsKey('KEY_ALIAS')
&& props.containsKey('KEY_PASSWORD')) {
android.signingConfigs.release.storeFile = file(props.getProperty('STORE_FILE'))
android.signingConfigs.release.storePassword = props.getProperty('STORE_PASSWORD')
android.signingConfigs.release.keyAlias = props.getProperty('KEY_ALIAS')
android.signingConfigs.release.keyPassword = props.getProperty('KEY_PASSWORD')
} else {
println 'signing.properties found but some entries are missing'
android.buildTypes.release.signingConfig = null
}
} else {
println 'signing.properties not found'
android.buildTypes.release.signingConfig = null
}
}
}
buildTypes …
Run Code Online (Sandbox Code Playgroud) 如何为不同的变体设置不同的签名配置?
例如,我们目前有两种版本的buildtypes Debug/Beta/Release,免费和付费,产生了6种变体.为了使它更容易一点,让我们忘记Debug变体,只关注freeBeta/paidBeta/freeRelease/paidRelease.
我想要的是,每个变体都使用单独的不同的signedConfig.
到目前为止,我能找到的唯一解决方案是将signingConfigs置于buildTypes中,以便所有Beta变体都具有相同的signingConfigs:
buildTypes {
beta {
signingConfigs.beta
}
release {
signingConfigs.release
}
}
Run Code Online (Sandbox Code Playgroud)
或者,使用flavor,在这种情况下,所有免费变体都具有相同的signingConfigs:
productFlavors {
free {
signingConfig signingConfigs.free
applicationId 'com.example.free'
}
paid {
signingConfig signingConfigs.paid
applicationId 'com.example.paid'
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在当前的productFlavor闭包中执行此操作?只能通过覆盖android.applicationVariants.all { variant ->
并根据某些命名方案或其他一些丑陋的黑客手动为每个应用程序变体应用signingConfig 来解决这个问题吗?
我也找到了这个答案,但它似乎不适用于最新的构建工具; 编译时我收到以下错误:
FAILURE:构建因异常而失败.
其中:构建文件'/home/dev/projects/app/build.gradle'行:61
出了什么问题:评估项目':app'时出现问题.
在ProductFlavor容器上找不到属性'free'.
我正在尝试为应用程序变体设置signingConfig
, manifestPlaceholders
, 。buildConfigField
我可以为每个构建类型设置它们或者!ProductFlavor 独立,但我需要的是根据 ProductFlavor和!构建类型。
buildTypes{
getByName("debug"){}
getByName("release"){}
create("staging"){}
}
productFlavors {
create("global"){}
create("local"){}
}
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,有 3 种不同的 buildType 和 2 种不同的 ProductFlavors。这意味着总共有 6 个 APK 变体。对于每个APK(globalRelease、globalStaging、globalDebug、localRelease、localStaging、localDebug),我想使用不同的signingConfig。我该如何设置?
尝试过: