Khoa Pham
Khoa Pham
Aug 13, 2018 · 2 min read
Source: JLT

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

*.iml/build
/gradle.properties
/local.properties
.gradle
.idea

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

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

String environmentKey(variable) {
for (Object var : binding.variables) {
if (var.value == variable) {
return System.getenv(var.key) ?: variable
}
}
return ""
}
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

#!/usr/bin/env bashcp $BUDDYBUILD_SECURE_FILES/gradle.properties $BUDDYBUILD_WORKSPACE/gradle.properties

Fantageek

Simple apps that make sense

Khoa Pham

Written by

Khoa Pham

My apps https://onmyway133.github.io/

Fantageek

Fantageek

Simple apps that make sense

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade