Gradle set absolute path value for keystore file

I would like to keep the directory out in the project directory. I do not want to store file paths inside the repository, so I delegated the values ​​to the corresponding gradle variables in ~/.gradle/gradle.properties I cannot get gradle to accept the absolute path, for example: /Users/username/.gradle/keystores/project/release.key or ~/.gradle/keystores/project/release.key

I tried: storeFile file(RELEASE_STORE_FILE) as well as storeFile new File(RELEASE_STORE_FILE)

none of them seem to work.

How to pass the absolute value of the path to the keystore file through the RELEASE_STORE_FILE variable?

 android { signingConfigs { release { storeFile file(RELEASE_STORE_FILE) storePassword RELEASE_STORE_PASS keyAlias RELEASE_ALIAS keyPassword RELEASE_KEY_PASS } } } 

and ~/.gradle/gradle.properties :

 RELEASE_STORE_FILE=/Users/username/.gradle/keystores/project/release.key RELEASE_STORE_PASS=****** RELEASE_ALIAS=****** RELEASE_KEY_PASS=****** 

In short: I want to pass the absolute value of the path to gradle.

+6
source share
3 answers

I got around this using a symlink

  • Create a keystore.lnk in the application module

    ln -s [path-to-keystore] keystore.lnk

  • Then use keystore.lnk in gradle.properties

    RELEASE_STORE_FILE = keystore.lnk (do not use quotation marks)

Now your gradle instructions will work.

+2
source

In the end, I used an interesting solution from this site.

The idea is to save the variables in a separate folder, which is stored in a remote repository .

In the file ~/.gradle/gradle.properties you put:

 Keys.repo=/Users/username/.signing 

where Keys.repo is the local path to the remote repository.

Later in /Users/username/.signing/YourProjectName.properties you have:

 RELEASE_STORE_FILE=/YourProjectName/release.keystore //in fact it a relative path RELEASE_STORE_PASS=xxxxx RELEASE_ALIAS=xxxxx RELEASE_KEY_PASS=xxxxx 

You need to save the release.keystore file in /Users/username/.signing/YourProjectName/release.keystore path

The configuration is used as follows:

 android { signingConfigs { debug { /* no changes - usual config style */ } release { if (project.hasProperty("Keys.repo")) { def projectPropsFile = file(project.property("Keys.repo") + "/YourProjectName.properties") if (projectPropsFile.exists()) { Properties props = new Properties() props.load(new FileInputStream(projectPropsFile)) storeFile file(file(project.property("Keys.repo") + props['RELEASE_STORE_FILE'])) storePassword props['RELEASE_STORE_PASS'] keyAlias props['RELEASE_ALIAS'] keyPassword props['RELEASE_KEY_PASS'] } } else { println "=======================================================" println "[ERROR] - Please configure release-compilation environment - eg in ~/.signing directory" println "=======================================================" } } } } 
+1
source

Found a solution there: https://gist.github.com/gabrielemariotti/6856974

In short, you should correctly parse the file containing the path to the keystore. Change your gradle module with the following lines. Firstly, this is a way to create signConfigs based on the contents of the keystore.properties file:

 signingConfigs { release { def Properties props = new Properties() def propFile = new File('path/to/your/keystore.properties') //absolute path to keystore.properties if (propFile.canRead()) { props.load(new FileInputStream(propFile)) if (props != null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') && props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) { android.signingConfigs.release.storeFile = file(props['STORE_FILE']) android.signingConfigs.release.storePassword = props['STORE_PASSWORD'] android.signingConfigs.release.keyAlias = props['KEY_ALIAS'] android.signingConfigs.release.keyPassword = props['KEY_PASSWORD'] } else { println 'keystore.properties found but some entries are missing' android.buildTypes.release.signingConfig = null } } else { println 'keystore.properties not found' android.buildTypes.release.signingConfig = null } } } 

And then add the signConfig parameter to your buildType release:

 buildTypes { ... release { ... signingConfig signingConfigs.release } } 

An example keystore.properties file for this solution:

 STORE_FILE=absolute//path//to//store STORE_PASSWORD=yourPass KEY_PASSWORD=keysPass KEY_ALIAS=aliasName 

This worked for me (Android Studio 3.0.1, gradle 4.1, Windows 10).

0
source

All Articles