crmackey crmackey - 5 months ago 22
Android Question

Using environment variables for Gradle builds in Android Studio

We decided to use GitHub as our version control. I know the Gradle build scripts use certain paths, such as the Android SDK path in the

local.properties
file.

Since this path will differ between the five of us, I think the projects will fail to build on my teammates' machines when they pull changes from GitHub. Is this correct?

If so, can we all make an environment variable called something like
ANDROID_SDK
and use that for the
sdk.dir
in the
local.properties
? Would the project properly build on all of our machines if we used the environment variable? Are there any other places where we may need to set
a similar environment variable? Will this work? If so, how do we do this?

I am not sure if this is the best way to go about setting up a team project for Android. I'm looking for suggestions on a best practice for this.

Answer

Is this correct?

No, because IMHO local.properties should not be in your Git repo. The standard Android Studio .gitignore file (created when you create the project) has local.properties, meaning that local.properties would not be committed to your repo.

As Doug Stevenson points out in a comment, local.properties is generated when you import a project. It will be driven by Android Studio settings.

can we all make an environment variable called something like ANDROID_SDK and use that for the sdk.dir in the local.properties?

Not for use with Android Studio, at least the last I tried it. For command-line Gradle builds, that works fine, but Android Studio does not pass the environment to its forked Gradle process.