I have been following this guide to allow loading the secrets for my Android keystore properties from a dedicated file.
Basically, the build.gradle file contains:
def keystorePropertiesFile = rootProject.file("testandroidpacketcapture/keystore.properties");
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
// ...
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
}
}
This works as long as the keystore.properties file exists. But for debug builds, or for developers who do not have access to the keystore, I would like to make this loading of the properties optional.
How could I define that variable only depending on whether that file is available?
I could load the contents only if the file exists(), but then the file() call in storeFile will still fail, because it is not defined.