Last active
June 5, 2020 08:45
-
-
Save mirland/6277791f7356df04d73e42056195fd63 to your computer and use it in GitHub Desktop.
Script to manage android secret keys
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: rootProject.file('read_secrets.gradle') | |
apply plugin: 'com.android.application' | |
.... | |
android { | |
defaultConfig { | |
buildConfigField 'String', 'SOMETHING_SECRET', getEnvVariable('SOMETHING_SECRET') | |
} | |
signingConfigs { | |
prod_release { | |
storeFile file(getEnvVariable('KEYSTORE_FILE_PATH')) | |
storePassword getEnvVariable('KEYSTORE_STORE_PASSWORD') | |
keyAlias getEnvVariable('KEYSTORE_ALIAS') | |
keyPassword getEnvVariable('KEYSTORE_ALIAS_PASSWORD') | |
} | |
} | |
.... | |
buildTypes { | |
release { | |
buildConfigField 'String', 'LIBRARY_RELEASE_SECRET', getEnvVariable('LIBRARY_RELEASE_SECRET') | |
.... | |
} | |
} | |
productFlavors { | |
//noinspection GroovyMissingReturnStatement | |
dev { | |
buildConfigField 'String', 'LIBRARY_DEV_API_KEY', getEnvVariable('LIBRARY_DEV_API_KEY') | |
.... | |
} | |
prod { | |
buildConfigField 'String', 'LIBRARY_PROD_API_KEY', getEnvVariable('LIBRARY_PROD_API_KEY') | |
signingConfig signingConfigs.prod_release | |
.... | |
} | |
} | |
} |
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
# Keysore setup | |
KEYSTORE_FILE_PATH=something.jks | |
KEYSTORE_STORE_PASSWORD=something | |
KEYSTORE_ALIAS=something | |
KEYSTORE_ALIAS_PASSWORD=something | |
# Secret api keys | |
SECRET_API_KEY="something" |
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
final def PROPERTY_FILE = file(rootProject.file('app/keys.properties')) | |
final def PROPERTIES = new Properties() | |
if (PROPERTY_FILE.exists()) { | |
PROPERTY_FILE.withInputStream { PROPERTIES.load(it) } | |
} | |
ext.getEnvVariable = { key, defaultValue = null -> | |
def value = PROPERTIES[key] | |
if (value != null) { | |
return value | |
} | |
value = project.hasProperty(key) ? project.getProperty(key) : System.getenv(key) | |
value = value?.trim() ? value : null | |
if (value == null && defaultValue == null) { | |
logger.warn("Variable '$key' is not defined.") | |
} | |
return value ?: defaultValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment