3

I'm using retrolambda in an Android project. I set two env variables for export in my .bashrc, JAVA7_HOME and JAVA8_HOME that point to the absolute paths of both Java SDKs, after which I source'd .bashrc again.

However, trying to compile my project gives me an error. When I print out the results of System.getEnv("JAVA7_HOME"), I get null back. However, curiously, when I run env and grep for the variables in my terminal, I see them there. Most strangely, not even assigning the path as a string to the JDKs directly seems to work. I have attempted a restart of both Android Studio and my computer just in case my changes to .bashrc didn't take effect, but nothing has worked.

Does anyone have any insight as to the problem, or what else I could try? I'm running Mac OS X for what it's worth.

Rome_Leader
  • 2,518
  • 9
  • 42
  • 73
  • 1
    "When I print out the results of System.getEnv("JAVA7_HOME")" -- um, print this from where? `build.gradle`? Your Java code that is running on an Android device? Somewhere else? – CommonsWare Jan 15 '16 at 20:22
  • From build.gradle. I can't print anything from the device since I get a compiler error. – Rome_Leader Jan 16 '16 at 15:54
  • 1
    AFAIK, environment variables are not passed into the forked Gradle process used by Android Studio. – CommonsWare Jan 16 '16 at 15:56
  • Possible duplicate of [Setting environment variables in OS X?](https://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x) – Sagi Iltus Jan 21 '18 at 15:01

1 Answers1

1

Sample: How to set environment variables

Windows: In a terminal window, type the following:

set HTTP_PROXY=myserver:1981

Mac and Linux: In a terminal window, type the following:

export HTTP_PROXY=myserver:1981

Alternately, add it to your ~/.bash_profile file and source the file as follows:

export HTTP_PROXY=myserver:1981
source ~/.bash_profile
Job M
  • 3,331
  • 2
  • 19
  • 26