[java] Android Studio was unable to find a valid Jvm (Related to MAC OS)

I am unable to start my Android Studio for Android development on Mac OS (10.10.1 - Yosemite)

This question is related to java android macos android-studio ide

The answer is


As a novice user it took me a while to understand how to fix this in a correct way. After searching and understating many answers on SO I came out with the Following steps that you need to follow to fix the issue.

Please Note:

Although the simplest solution is to update the Info.plist of android studio . But it is not recommended and not the correct way to fix it .

Official statement- "Please note: Do not edit Info.plist to pick a different version. That will break not only the application signature, but also future patch updates to your installation."

First Solution : If you run your Android Studio from command line, you can add these two lines into your .bash_profile

$ export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk

$ open /Applications/Android\ Studio.app

From next time whenever you open your terminal your studio will start automatically.

Second Solution: If you want to run Android Studio from UI(by click on Icon) follow below steps:

  1. Open script editor on mac(one can find it in spotlight)
  2. Copy past the below line

    do shell script "launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk"

Note :- Change the jdk version according to your version. To check which version you are using open terminal and run the following command

java -version

3.Now save (?+s) as File format: Application. Finally open System Settings ? Users & Groups ? Login Items and add your new application that you have just created.

  1. Log-off and login again or you can run that application manually as well..

woolaaaa…Its done.

References :

Antonio Jose's answer

ruario's answer


Just install this guy here

http://support.apple.com/kb/DL1572?viewlocale=en_US&locale=en_US

and you should be good.


Android Studio will read settings from the file ~/Library/Preferences/AndroidStudio/idea.properties. I created this file and in it have the path to my jdk :

STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk

No editing of the Info.plist necessary!


I was able to get it to work by editing the info.plist changing 16* to 16+. Tried using the recommended method but that failed.


I resolved this issue by changing the JVM version in the Info.plist file to 1.7*


Java was uninstalled when I updated to OS X El Capitan.

See screenshot of terminal before and after I reinstalled Java.

enter image description here

To reinstall Java I followed this link that was provided in the Android Studio dialog box.

enter image description here

Android Studio ran again after the Java installation was reinstalled.


I have same problem and fixed with this way:

You should install Java from Official Apple page.

http://support.apple.com/kb/DL1572


On Android Tools Project Site, there is a great explanation Mac OSX JDK Selection. It fixed my problem. In summary:

Android Studio requires two different JDKs:

  • The version of Java that the IDE itself runs with.
  • The version of the JDK that it uses to get the Java compiler from

These two can be (and usually are) the same, but you can configure them individually. And on OSX in particular, they will often be different.

and for Yosemite (Mac OSX 10.10) Issues:

First, please make sure that you have the latest version of Java 6 installed; in some cases that has fixed the problems: http://support.apple.com/kb/DL1572

If not, try running a recent version of Java 7 or Java 8 instead by setting STUDIO_JDK as described above. That is reported to have fixed the other problems (though you will get the font rendering shown for Java 8 above.)


  1. Install newest JDK (8u102 current)
  2. Set envirionment variable STUDIO_JDK (java_home outputs the Java home dir and sed strips two folders to get the jdk dir)

    launchctl setenv STUDIO_JDK `/usr/libexec/java_home -version 1.8 | sed 's/\/Contents\/Home//g'`

  3. Launch Android Studio like you would normally

Set STUDIO_JDK on every reboot

The above steps only works for the current session. Here is how to create a plist file in /Library/LaunchDaemons that runs the above command on every boot:

sudo defaults write /Library/LaunchDaemons/com.google.studiojdk Label STUDIO_JDK
sudo defaults write /Library/LaunchDaemons/com.google.studiojdk ProgramArguments -array /bin/launchctl setenv STUDIO_JDK `/usr/libexec/java_home | sed 's/\/Contents\/Home//g'`
sudo defaults write /Library/LaunchDaemons/com.google.studiojdk RunAtLoad -bool TRUE

Found out about the plist trick thanks to http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-launchd-plist/


i'm dealing with the same problem and i get it worked.

it is probably that your jdk version is not right.

now i installed jdk1.8 and it is ok now.


For those who were having trouble creating a script that launched on startup, as an alternative you can add this .plist to your LaunchAgents folder. This may be a more appropriate way of adding environment variables to the system since Yosemite decided to do away with launchd.conf. This should also work across user accounts due to the nature of the LaunchAgents folder, but I haven't tested that.

To do this, create a .plist file with the following name and path:

/Library/LaunchAgents/setenv.STUDIO_JDK.plist

and the contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
            <string>setenv.STUDIO_JDK</string>
        <key>ProgramArguments</key>
            <array>
                <string>sh</string>
                <string>-c</string>
                <string>
                    launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk
                </string>
            </array>
        <key>RunAtLoad</key>
            <true/>
        <key>ServiceIPC</key>
            <false/>
        <key>LaunchOnlyOnce</key>
            <true/>
        <key>KeepAlive</key>
            <false/>
    </dict>
</plist>

Then change file properties by running the following commands in Terminal:

sudo chmod 644 /Library/LaunchAgents/setenv.STUDIO_JDK.plist

sudo chown root /Library/LaunchAgents/setenv.STUDIO_JDK.plist

sudo chgrp wheel /Library/LaunchAgents/setenv.STUDIO_JDK.plist

Notes:

1) You may need to change 'jdk1.8.0_25.jdk' to match the version that you have on your computer.

2) I tried to use "jdk1.8.*.jdk" to try and account for varying Java * versions, but when I opened Android Studio I got the no JVM error even though if you run "echo $STUDIO_JDK" it returns the correct path. Perhaps someone has some insight as to how to fix that issue.


You can implement the STUDIO_JDK solution using your user's launch agents. This involves creating one plist file in your LaunchAgents directory, located at ~/Library/LaunchAgents

Create a new file, ~/Library/LaunchAgents/UNIQUE_KEY.plist, where UNIQUE_KEY is just an identifier. I use com.username.androidstudio.

Copy the following text into your new plist file and modify it according the instructions below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>UNIQUE_KEY</string>
   <key>ProgramArguments</key>
   <array>
      <string>sh</string>
      <string>-c</string>
      <string>launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>

You will need to make two modifications:

  1. Change UNIQUE_KEY to match your filename (without the .plist extension).
  2. Verify your JDK path is correct and change if necessary. I'm using 7u71 in this example.

This is the same underlying solution as Antonio Jose's answer. It sets the STUDIO_JDK environment variable based on the Android Studio version 1.0 RC3 release notes. This solution uses the LaunchAgents directory rather than AppleScript to set the environment variable. As such it is mostly a difference in how your order and organize your system and environment variables.


Do not edit the plist. These instructions worked for me the first time I installed Android Studio a few months ago as well as just today. (1/21/2015)

All you need to do is a few simple things, although they aren't really listed on Google's website.

  1. First you need Java installed. this is not the JDK, it is seperate. You can get that from this link. If you don't have this it will probably throw an error saying something like "no JVM installed."
  2. Second you need the Java JDK, I got JDK 7 from this link. Make sure to choose the Mac OS X link under the Java SE Development Kit 7u75 heading. If you don't have this it will probably throw an error saying something like "no JDK installed."
  3. If you haven't already installed Android Studio, do that. But I'm sure you've already done that by now.

Edit the android studio's Info.plist file in the package so that it uses 1.7 or whatever JVMVersion you have installed. Changing the JVMVersion to 1.6+ instead of 1.6* as hasternet answered above should work too.

The above works but is not recommended see RC3 Release Notes

As of RC 3, we have a better mechanism for customizing properties for the launchers on all three platforms. You should not edit any files in the IDE installation directory. Instead, you can customize the attributes by creating your own .properties or .vmoptions files in the following directories. (This has been possible on some platforms before, but it required you to copy and change the entire contents of the files. With the latest changes these properties are now additive instead such that you can set just the attributes you care about, and the rest will use the defaults from the IDE installation).

see Android Studio failed to load JVM on Mac OSX (Mavericks)


"On Mac OS, run Android Studio with Java Runtime Environment (JRE) 6 for optimized font rendering. You can then configure your project to use Java Development Kit (JDK) 6 or JDK 7."

This was listed in http://developer.android.com/sdk/index.html under the system requirements for Mac OS X.

Once you install Java 6 (not the JDK) from Apple as per Alonso C. Licks, you should be able to open Android Studio and reconfigure as you wish without having to mess around in the terminal, info.plist file, or other libraries.


I ran this bad boy:

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

On Mac OS X Yosemite just install:

Java SE Development Kit 8

and

Java Version 8 Update 25

It's all, work for me too! like gehev said , so simple !


Note that this last variable allows you to for example run Android Studio with Java 7 on OSX (which normally picks Java 6 from the version specified in Info.plist):

$ export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk

$ open /Applications/Android\ Studio.app

Worked for me


Change this key in the Info.plist

I changed from

<key>JVMVersion</key>
<string>1.6*</string>

to

<key>JVMVersion</key>
<string>1.8*</string>

and it worked fine now..

Edited:
Per the official statement as mentioned above by hasternet and aried3r, the solution by Antonio Jose is correct.

Thanks!


Try downloading the Java from Apple Support Page: http://support.apple.com/kb/DL1572 if that doesn't work for you or fails to load (very common issue), just follow this link to download and install the Java version you need:

http://support.apple.com/downloads/DL1572/en_US/JavaForOSX2014-001.dmg

That's it.


I have downloaded Intellij Idea. When I try to install Intellij, a pop-up appeared that my Mac is missing with Java RE, do you want to download it? After I downloaded missing package using Intellij, I could open Android Studio.


I had previously uninstall Java 6 and install Java 7, Android Studio was working okay, then I upgraded Android Studio and I had the issue everyone is having. Today, I uninstalled Java 7 and installed Java 8 from Oracle. Then I uninstall Android Studio and installed the latest. Everything is working for me now


This one work for me, very simple, just export the environmentable var. but make sure u have the valid JVM first though.

https://code.google.com/p/android/issues/detail?id=82378


On Mac OS X Yosemite just install:

Java SE Development Kit 8

and

Java Version 8 Update 25

It's all, work for me!


As @Gerard suggested, I summerise my original comment (https://stackoverflow.com/a/27370525/763459) as an Answer, hope it can help others who are annoyed by this issue.

There's a way without running the AppleScript: edit .bash_profile (if this file doesn't exist, please create a new one , as @Gerard suggested, you can to use source .bash_profile for the first time).

  • Install the legacy Java (may be neccessary) http://support.apple.com/kb/DL1572

  • Put export STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk

  • Then quit terminal (or any text editors you're using to edit this file), run the Android Studio and viola

Tested with OSX 10.10 and Android 1.0.1


[Update]
This is fixed in Android Studio 1.1 https://issuetracker.google.com/issues/37015035

In the next version of Android Studio, if no java 6 is found but 7 (or greater) is found then it will use that instead. We still recommend running studio with Java 6 due to improved font rendering, but there is no work around needed if, for example, only java 8 is found.

[End Update]

From Android Studio 1.0 RC3 Notes

As of RC 3, we have a better mechanism for customizing properties for the launchers on all three platforms. You should not edit any files in the IDE installation directory. Instead, you can customize the attributes by creating your own .properties or .vmoptions files in the following directories. (This has been possible on some platforms before, but it required you to copy and change the entire contents of the files. With the latest changes these properties are now additive instead such that you can set just the attributes you care about, and the rest will use the defaults from the IDE installation).

However there is no explanation about what options are.

After searching a little I found this
Adjusting VM Options for Android Studio on Mac
IntelliJ IDEA 14.0.0 Web Help/File IDEA.Properties

However no luck with that.

Fortunately I was able to resolve it on Yosemite using environment variables as said in the 1.0 RC3 Release Notes.

You can also place use environment variables to point to specific override files elsewhere:
STUDIO_VM_OPTIONS, which vmoptions file to use
STUDIO_PROPERTIES, which property file to use
STUDIO_JDK, which JDK to run studio with

This was a little tricky because Android Studio is not a command line application so I had to use a AppleScript command to set the environment variable when login. More info here

This is my launchctl command for the command line.

launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk

And this my AppleScript (remember to save it as an Application)

do shell script "launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk"

About launchctl, see here


I am using Mac OS X 10.10 also. And to fix this problem.

  1. Open Android Studio application package content (by right click on Android Studio icon in Application folder)
  2. Open file Infor.plist
  3. Search and replace:

    <key> JVM version</key>
    <string>1.6*</string>
    

replaced by:

    <key> JVM version</key>
    <string>1.6+</string>

That's it!


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK

Examples related to ide

How can I view the Git history in Visual Studio Code? How to ignore a particular directory or file for tslint? How do I completely rename an Xcode project (i.e. inclusive of folders)? Where is the visual studio HTML Designer? How to disable gradle 'offline mode' in android studio? Android studio Error "Unsupported Modules Detected: Compilation is not supported for following modules" Android Studio was unable to find a valid Jvm (Related to MAC OS) QtCreator: No valid kits found Difference between WebStorm and PHPStorm package android.support.v4.app does not exist ; in Android studio 0.8