6

I am having a KEY_STRING as system variable in mac OSX and Windows. Which has absolute path to my keystore.

~/.bash_profile entry would be

export KEY_STRING =~/config/release-signing.keystore

Same path setup in each of my team mates machines[Windows/OSX/Linux].

My Gradle script to access this variable would be

def keystorePath = System.getenv("KEY_STRING");
println keystorePath;

This script works fine in Windows in both console and android studio.

My problem specific to mac android studio.

If I run the build in terminal which is working fine and reads the env variable.

But when I do gradle sync or set up run configuration [Gradle task] it cannot resolve the variable.

I have reported this issue to Google as well.

Again here is the quick summary:

  • Setup an environment variable in ~/.bash_profile
  • Read it anywhere in build.gradle

    def keystorePath = System.getenv("KEY_STRING"); println keystorePath;

  • Add gradle task in configuration. Adding custom gradle task to android studio

  • It is not reading the environment variable.
Mahendran
  • 2,719
  • 5
  • 28
  • 50

1 Answers1

6

None of the OSX apps can read the environment variable.

As per this answer https://stackoverflow.com/a/14285335/981555

solution for my problem would be

launchctl setenv KEY_STRING ~/config/release-signing.keystore

This should be set before launching Android studio.

Community
  • 1
  • 1
Mahendran
  • 2,719
  • 5
  • 28
  • 50
  • 2
    To add to this answer, I was actually able to get the environment variables set automatically on OSX Login by using a combination of AppleScript saved as Application, Started on Login Items in Users and Groups, and using this syntax: `do shell script "launchctl setenv ANDROID_HOME /users/$(whoami)/Library/Android/sdk"`. This runs the launchctl setenv when the user logs in and then applications and terminal can see the environment variables – Dr. Andrew Burnett-Thompson May 05 '16 at 19:04