RED_ RED_ - 2 months ago 54
Android Question

Read Jenkins environment variables in Android project? Sign APK for automated builds

Thought I would find the answer through searching but no luck. I am planning on automating my build process and uploading builds to

Crashlytics Beta
via
fastlane
on my Jenkins server.
Crashlytics beta
requires signed APKS, but of course I don't want to add my
keystore
and password directly into my
build.gradle
file, and then into version control.

I was pointed in the direction of Jenkins env variables. This is what I have in my Android project:

signingConfigs {
release {
storeFile file(ANDROID_KEYSTORE)
storePassword ANDROID_STORE_PASSWORD
keyAlias ANDROID_KEY_ALIAS
keyPassword ANDROID_STORE_PASSWORD
}
}


Then in my
gradle.properties
file I have the following:

ANDROID_KEYSTORE=$ANDROID_KEYSTORE
ANDROID_STORE_PASSWORD=$ANDROID_STORE_PASSWORD
ANDROID_KEY_ALIAS=$ANDROID_KEY_ALIAS


When I try to build my project on
jenkins
via
fastlane
, I get the following error:

* What went wrong:
Execution failed for task ':app:validateReleaseSigning'.
> Keystore file /Users/macmini/.jenkins/workspace/AndroidProject/app/$ANDROID_KEYSTORE not found for signing config 'release'.


One other thing, I have env in terminal and it showed me all the system env variables, the ones I had defined were not there, so I'm not entirely sure where
Jenkins
puts them. Do I need a direct path? What would that be?

Any help is appreciated, thanks!

Answer

Mike from Fabric and Fastlane here.

I don't believe that this:

ANDROID_KEYSTORE=$ANDROID_KEYSTORE
ANDROID_STORE_PASSWORD=$ANDROID_STORE_PASSWORD
ANDROID_KEY_ALIAS=$ANDROID_KEY_ALIAS

will work in the way you're hoping for. If you've already got the environment variables set with the values you want, you can use System.env.ANDROID_KEYSTORE etc. within your build.gradle and skip putting anything else in gradle.properties.