-
-
Save dingmingxin/d84634e1b9e2efed9c74d581c58d2a12 to your computer and use it in GitHub Desktop.
Auto switch signing configs for multiple-releases-product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply from: 'release.gradle' | |
android{ | |
productFlavors { | |
dev { | |
//... | |
} | |
//... | |
} | |
signingConfigs { | |
config { | |
storeFile file(signing.storeFile) | |
storePassword signing.storePassword | |
keyAlias signing.keyAlias | |
keyPassword signing.keyPassword | |
} | |
} | |
buildTypes { | |
debug { | |
signingConfig signingConfigs.config | |
} | |
release { | |
signingConfig signingConfigs.config | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher | |
import java.util.regex.Pattern | |
//Add `releaseMachine=true` to the `local.properties` file of the release computer. | |
Properties properties = new Properties() | |
properties.load(project.rootProject.file('local.properties').newDataInputStream()) | |
def isReleaseMachine = properties.containsKey('releaseMachine') ? properties.getProperty('releaseMachine').toBoolean() : false | |
ext.signingConfigs = [ | |
debug : [ | |
storeFile : "debug-key-store-filename", | |
storePassword: "debug-password", | |
keyAlias : "debug-key-alias", | |
keyPassword : "debug-key-password" | |
], | |
release: [ | |
storeFile : "release-key-store-filename", | |
storePassword: "release-password", | |
keyAlias : "release-key-alias", | |
keyPassword : "release-key-password" | |
], | |
dev : [ | |
storeFile : "dev-keystore-filename", | |
storePassword: "dev-password", | |
keyAlias : "dev-key-alias", | |
keyPassword : "dev-key-password" | |
], | |
//... | |
] | |
def getCurrentFlavor() { | |
Gradle gradle = getGradle() | |
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString() | |
println(tskReqStr) | |
Pattern pattern; | |
Pattern patternRelease = Pattern.compile("args=\\[.+?Release\\]") | |
def isRelease = patternRelease.matcher(tskReqStr).find() | |
if (tskReqStr.contains("assemble")) | |
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)") | |
else | |
pattern = Pattern.compile("generate(\\w+)(Release|Debug)") | |
Matcher matcher = pattern.matcher(tskReqStr) | |
if (matcher.find()) | |
return [isRelease, matcher.group(1).toLowerCase()] | |
else { | |
println "NO MATCH FOUND" | |
return [isRelease, null]; | |
} | |
} | |
ext.signing = ext.signingConfigs.debug | |
def (isRelease, flavor) = getCurrentFlavor() | |
if (isRelease && isReleaseMachine) { | |
if (flavor == null || ext.signingConfigs[flavor] == null) { | |
ext.signing = ext.signingConfigs.release | |
} else { | |
ext.signing = ext.signingConfigs[flavor] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment