Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX Android studio's gradle cannot read .bash_profile environment variable [duplicate]

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.
like image 900
Mahendran Avatar asked Sep 03 '15 13:09

Mahendran


1 Answers

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.

like image 135
Mahendran Avatar answered Oct 23 '22 05:10

Mahendran