BuddyBuild and gradle.properties
Issue #109
People advise against storing keys inside build.gradles
. We should store them on 1Password and populate our gradle.properties
, so don’t track this file in git. Here is .gitignore
file
1 | *.iml |
There are several ways to help BuddyBuild
know about our gradle.properties
1. Using Environment variables
But when configuring the project on BuddyBuild
, it complains about key not found. The solution is to use Environment variables
Then in your build.gradle
, you can
1 | buildConfigField 'String', 'MY_KEY', System.getenv("MY_KEY") ?: MY_KEY |
This is because gradle does not know about environment variables. The System.getenv("MY_KEY")
is for BuddyBuild, and the default MY_KEY
is for gradle.properties
.
Next is to remove this duplication. We can use Groovy Binding. build.gradle
does the import import groovy.lang.Binding
automatically for us
1 | String environmentKey(variable) { |
1 | buildConfigField 'String', 'MY_KEY', environmentKey(MY_KEY) |
2. Using Secured File 👍
BuddyBuild allows us to define Secured File, here we can upload our gradle.properties
And we can use Prebuild script to copy this secured file to our project. BuddyBuild suggests using buddybuild_prebuild.sh
but then build fails in Build file '/tmp/sandbox/workspace/app/build.gradle'
So, create a script called buddybuild_postclone.sh
1 |
|