Android Gradle keyAlias ​​variables stored in a separate file

I am developing an Android project based on Jenkins CI. All signature keys are stored in a separate repository in the encrypted gradle.properties file. In the project repository, the gradle.properties file is tracked and (obviously) contains no keys.

Here is a build.gradle example for the project part for the project module:

signingConfigs { release { keyAlias KEY_ALIAS storeFile file(KEYSTORE_PATH) storePassword KEYSTORE_PASSWORD keyPassword MOBILE_KEY_PASSWORD } 

My question is: how can I store these keys on my local development machine and be able to create a project without modifying the gradle.properties file and modifying the assembly files?

+5
source share
2 answers

I managed to find out. According to Gradle docs , the configuration is applied in the following order:

gradle.properties in the project root directory.

gradle.properties in the GRADLE_USER_HOME directory.

system properties, for example. when -Dgradle.user.home is set to command line.

So, all I had to do was add the custom gradle.properties file to the gradle home directory (/USERNAME/.gradle/ on Mac)

0
source

first create a file called external.properties in the project root directory.

then check if this file exists

 def externalPropertyFile = file("${rootProject.projectDir.path}${File.separator}external.properties") if (!propertyFile.exist()) { throw new GradleException("external.property file doesn't exist") } 

check if properties exist in the current context if you do not load the properties file

 if (!rootProject.ext.has("externalProperties")) { rootProject.ext { externalProperties = new Properties() externalProperties.load(propertyFile.newReader()) } } 

You can do the same check in signConfigs and omit the release build if properties are not available:

 signingConfigs { if (rootProject.ext.has("externalProperties")) { release { keyAlias rootProject.externalProperties.KEY_ALIAS storeFile file(rootProject.externalProperties.KEYSTORE_PATH) storePassword rootProject.externalProperties.KEYSTORE_PASSWORD keyPassword rootProject.externalProperties.MOBILE_KEY_PASSWORD } } } 
0
source

Source: https://habr.com/ru/post/1275170/


All Articles