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.
7
  • Not at all.. It is specific to android studio's gradle. It cannot read the variable. Commented Sep 3, 2015 at 13:18
  • 1
    ... because OSX app's don't have access to environment variables set in .bash_profile. Commented Sep 3, 2015 at 13:34
  • Is there any workaround to put these env variable? I didn't want to mess my build.gradle Commented Sep 3, 2015 at 13:40
  • Did you read the answer I linked? Commented Sep 3, 2015 at 14:02
  • Yes.. I read it's no longer working in Yosmite with 30 upvotes in comment. Commented Sep 3, 2015 at 14:12

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.