I am trying to setup signing process so that keystore password and key password are not stored in the project\'s build.gradle
file.
Cur
This question has received many valid answers, but I wanted to share my code which may be useful for library maintainers, because it leaves the original build.gradle
quite clean.
I add a folder to the module directory which I gitignore
. It looks like this:
/signing
/keystore.jks
/signing.gradle
/signing.properties
keystore.jks
and signing.properties
should be self explanatory. And signing.gradle
looks like this:
def propsFile = file('signing/signing.properties')
def buildType = "release"
if (!propsFile.exists()) throw new IllegalStateException("signing/signing.properties file missing")
def props = new Properties()
props.load(new FileInputStream(propsFile))
def keystoreFile = file("signing/keystore.jks")
if (!keystoreFile.exists()) throw new IllegalStateException("signing/keystore.jks file missing")
android.signingConfigs.create(buildType, {
storeFile = keystoreFile
storePassword = props['storePassword']
keyAlias = props['keyAlias']
keyPassword = props['keyPassword']
})
android.buildTypes[buildType].signingConfig = android.signingConfigs[buildType]
And the original build.gradle
apply plugin: 'com.android.application'
if (project.file('signing/signing.gradle').exists()) {
apply from: 'signing/signing.gradle'
}
android {
compileSdkVersion 27
defaultConfig {
applicationId ...
}
}
dependencies {
implementation ...
}
As you can see, you don't have to specify the buildTypes at all, if user has access to a valid signing
directory, he just puts it in the module and he can build a valid signed release application, otherwise it just works for him like it would normally do.