Created
June 26, 2015 14:41
-
-
Save Sloy/3de0962942236c1eae9d to your computer and use it in GitHub Desktop.
Automatic apk signing for CI
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
android { | |
... | |
signingConfigs { | |
release { | |
storeFile file('../certs/release.keystore') | |
def (releaseKeystorePassword, releaseKeyAlias, releaseKeyPassword) = signingConfig() | |
storePassword releaseKeystorePassword | |
keyAlias releaseKeyAlias | |
keyPassword releaseKeyPassword | |
} | |
} | |
} | |
/** | |
* Tries to read signing values form a properties file, and fallbacks to environment variables if they are not found | |
* @return keystorePassword , keyAlias, keyPassword | |
*/ | |
def signingConfig() { | |
signingConfigFromFile() ?: signinConfigFromEnvironment() | |
} | |
/** | |
* Reads signing values form a environment variables | |
* @return keystorePassword , keyAlias, keyPassword | |
*/ | |
def signinConfigFromEnvironment() { | |
println '-> signinConfigFromEnvironment' | |
[System.getenv('STORE_PASSWORD'), System.getenv('KEY_ALIAS'), System.getenv('KEY_PASSWORD')] | |
} | |
/** | |
* Reads signing values form a properties file | |
* @return keystorePassword , keyAlias, keyPassword | |
*/ | |
def signingConfigFromFile() { | |
println '-> signingConfigFromFile' | |
def Properties props = new Properties() | |
def propFile = file('signing.properties') | |
if (propFile.canRead()) { | |
props.load(new FileInputStream(propFile)) | |
if (props != null && | |
props.containsKey('STORE_PASSWORD') && | |
props.containsKey('KEY_ALIAS') && | |
props.containsKey('KEY_PASSWORD')) { | |
def keystorePassword = props['STORE_PASSWORD'] | |
def keyAlias = props['KEY_ALIAS'] | |
def keyPassword = props['KEY_PASSWORD'] | |
return [keystorePassword, keyAlias, keyPassword] | |
} else { | |
println 'signing.properties found but some entries are missing' | |
} | |
} else { | |
println 'signing.properties not found' | |
} | |
return null | |
} |
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
#Do not commit | |
STORE_PASSWORD=storePassword | |
KEY_ALIAS=keyAlias | |
KEY_PASSWORD=keyPassword |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment