Fix for Android Studio was unable to find valid JVM on Mac OS X

If Android Studio complains saying Java not found then you need to help Android Studio locate your JVM by setting the STUDIO_JDK environment variable.

To find your installed JDK execute

/usr/libexec/java_home

You should see similar output to the following

/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home

If your on an older version of Mac OS X then you can try navigating to the default location to find your JDK path

cd /Library/Java/JavaVirtualMachines/

Once you have found your JDK path, you can immediately set your STUDIO_JDK variable by executing the launchctl command with your JDK path.

launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk

Paste it into your .profile to run the command automatically at startup.

cd ~
vi .profile
launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk

Source it to have your changes take effect immediately

source .profile

Notes

Using launchctl instead of export to set STUDIO_JDK will allow Android Studio to be launched from the OS X GUI interface. If set with export, you would have to open Android Studio from the command line using the open command. If your using Zsh then paste the launchctl line in your .zshrc file instead.

Further Reading:

https://developer.apple.com/library/mac/qa/qa1170/_index.html http://tools.android.com/tech-docs/configuration/osx-jdk