[Guide] How To Install And Setup Sun JDK 6 In Ubuntu For Android

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[Guide] How To Install And Setup Sun JDK 6 In Ubuntu For Android

7,495 Views
freewaymad
Contributor IV

Hi,

I decided to write this as a reference to help install and setup the proper JDK for building Android. NOTE --- this can also be found here: [GUIDE] Setup Android Development Environment on Ubuntu 14.04 Trusty Tahr. I know this works for Ubuntu 12.04 (Precise) up to 14.04 (Trusty Tahr). I will also show a variation which is (in my opinion) easier to get the JDK. One more thing to note, there are couple of things I will point out that are needed to resolve build issues with Kit Kat 4.4. On with the guide.

Installing Sun JDK 6

Add PPA to system

$ sudo add-apt-repository ppa:webupd8team/java


Download & install java

$ sudo apt-get update && sudo apt-get install oracle-java6-installer


CHECK

$ java -version

You should see something like:

java version "1.6.0_45"

Java(TM) SE Runtime Environment (build 1.6.0_45-b06)

Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

If not (I have had trouble with this i the past), do to this variation:

http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-41940...

(in your browser and manually download)

You will have to login or setup an account with Oracle if you do not have one.

Put the "jdk-6u45-linux-x64.bin" in the home directory.

We need to run the binary and move it to a shared location by opening a terminal and typing:

$ chmod +x jdk-6u45-linux-x64.bin

$ sudo ./jdk-6u45-linux-x64.bin

$ sudo mv jdk1.6.0_45 /usr/lib/jvm/

Now you have to install all binaries and give them highest priority, This will also overwrite the previous version of Java Binaries in your computer:

$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_45/bin/java 1

$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_45/bin/javac 1

$ sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_45/bin/javaws 1

$ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.6.0_45/bin/jar 1

$ sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk1.6.0_45/bin/javadoc 1

$ sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.6.0_45/bin/javap 1  (NOTE - This is needed to compile Kit Kat 4.4)

(Most of the time after these commands, I basically get that the jdk is not there. Just run the binary and move it to a shared location using the three commands above again,install, and give them the highest priority again...its a pain, I know)

Now check if JDK 1.6 is selected on this:

$ sudo update-alternatives --config java

$ sudo update-alternatives --config javac

$ sudo update-alternatives --config javaws

$ sudo update-alternatives --config jar

$ sudo update-alternatives --config javadoc

$ sudo update-alternatives --config javap  (NOTE - This is needed to compile Kit Kat 4.4)

These six alternatives should all be selected.

Now the JDK is configured! To check if it is done

Execute this is Terminal:

$ java -version

Output will be similar to this:

java version "1.6.0_45"

Java(TM) SE Runtime Environment (build 1.6.0_45-b06)

Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

IF NOT, YOU MAY NEED TO RUN AGAIN

The JDK is now configured. You can now delete or save somewhere else "jdk-6u45-linux-x64.bin"  that is in the home directory.

Tags (2)
0 Kudos
0 Replies