0

I am trying to setup Android build environment for my Mac 10.8.3

I dont understand, Apple provide instructions on how to revert mac back to Java 1.6 here :

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

They are clear instructions that I followed.

Yet when I still get the following :

unknown-98:fe:94:3f:92:ce:~ newuser$ java -version java version "1.7.0_13" Java(TM) SE Runtime Environment (build 1.7.0_13-b20) Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

Please please help me solve this problem.

drlobo
  • 2,139
  • 5
  • 32
  • 42
  • I just installed Oracle JDK 7 and Eclipse 4.2.2 yesterday and everything works fine. – Victor KP Apr 05 '13 at 20:59
  • The linked guide just resets the Java runtime used for applets and other web content. It doesn't mention anything about reverting back to Java 6 for your standalone environment. – Perception Apr 05 '13 at 21:00
  • but u will need java 6 to compile the actual Android Source code itself. – drlobo Apr 05 '13 at 21:59

1 Answers1

1

The Mac comes with, and occasionally updates, JDKs 1.4 through 1.6. You can see the versions you have installed in this directory:

  • /System/Library/Frameworks/JavaVM.framework/Versions

This is how you change the JDK

1. Command Line Java

My Java is coming from /usr/bin/java, which points off to one of the versions in the 'Versions' dir described above. To change the version of the JDK you're getting here, use the Java Preferences application under Applications -> Utilities -> Java:

enter image description here

You can drag the JDK you'd like to the top and it should be reflected immediately from the command line: hostname% java -version java version "1.5.0_16" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_16-133, mixed mode) hostname% java -version java version "1.6.0_07" Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)

2. Scripts and Applications That Use Java

Generally, other built-in applications or one that you install will use the JAVA_HOME environment variable to pick a JDK. By default, you won't have this set, and Mac-specific versions of startup scripts will usually create one by using the CurrentJDK link in the Java 'Versions' directory. The steps to add environment variables are documented in this article, but I can save you a little time. Create a directory .MacOSX in your home directory and add a file called environment.plist. Here are the entire contents of my ~/.MacOSX/environment.plist file:

<!-- When changing this, also run Java Preferences and change there. -->
<key>JAVA_HOME</key>
<string>/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home</string>

With this value set, all processes started as you will have JAVA_HOME available to them. Since this file is read when you log in, you'll have to log out/in once after you create or edit this file.

Special case: NetBeans

The IDE I use is NetBeans, but the following idea probably applies to other large applications as well. When NetBeans is installed, it will pick a JDK to use and hard code it in a properties file. If you want it to rely on the JAVA_HOME that you're now setting in environment.plist, you just need to edit one file. Edit this file:

  • /Applications/NetBeans/NetBeans\ 6.5.app/Contents/Resources/NetBeans/etc/netbeans.conf

..and you can set the JDK by changing this line:

netbeans_jdkhome=$JAVA_HOME

Note that, as the netbeans.conf file points out, you can always force a different JDK to be used by specifying it on the command line when starting the IDE. For your copying and pasting pleasure, here is the command to use to start it from terminal (I'm giving the 'help' option in this case). If you're using a different version, autocomplete ought to help with the version part of the path:

  • /Applications/NetBeans/NetBeans\ 6.5.app/Contents/MacOS/netbeans --help

Recap

To recap, you can switch JDKs for your whole system by using the Java Preferences application along with changing the value in your environment.plist file. To switch on the fly, use the Preferences app and set a new value for JAVA_HOME in whatever terminal you're using, though some apps like NetBeans will still pick up the system value and you should specify the desired JDK on the command line.

Resources where I found this solution: https://blogs.oracle.com/bobby/entry/switching_jdks_on_mac

javing
  • 12,307
  • 35
  • 138
  • 211