Here is the complete step by step that I used to use the properties file to move both of my keys from the gradle.build file to a file that will not be included in any assemblies or repository.
1) Create gradle.properties (if you don't already have one).
The location for this file depends on your OS:
/home/<username>/.gradle/ (Linux) /Users/<username>/.gradle/ (Mac) C:\Users\<username>\.gradle (Windows)
2) Add an entry pointing to yourprojectname.properties file. (example for Windows)
yourprojectname.properties=c:\\Users\\<username>\\signing\\yourprojectname.properties
3) Create yourprojectname.properties file in the location specified in step 2 with the following information:
keystore=C:\\path\\to\\keystore\\yourapps.keystore keystore.password=your_secret_password
4) Modify the gradle.build file to point to yourprojectname.properties file to use the variables.
if(project.hasProperty("yourprojectname.properties") && new File(project.property("yourprojectname.properties")).exists()) { Properties props = new Properties() props.load(new FileInputStream(file(project.property("yourprojectname.properties")))) android { signingConfigs { release { keyAlias 'release' keyPassword props['keystore.password'] storeFile file(props['keystore']) storePassword props['keystore.password'] } debug { keyAlias 'debug' keyPassword props['keystore.password'] storeFile file(props['keystore']) storePassword props['keystore.password'] } } compileSdkVersion 19 buildToolsVersion "20.0.0" defaultConfig { applicationId "your.project.app" minSdkVersion 16 targetSdkVersion 17 } buildTypes { release { } } } } dependencies { ... }
5) Enjoy! Now all your keys will be outside the root of the directory, and yet you still have the joys of automation for each assembly.
If you get an error in the gradle.build file about the "requisite" variable, because you are not executing the "android {}" block in the very first if state, where the props variable gets so just move the entire android section {...} to the condition, in which the attribute variable is assigned, then try again.
I gathered these steps together from the information I found here and here .
source share