How to install misc JDK in Ubuntu for Android build

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

How to install misc JDK in Ubuntu for Android build

How to install misc JDK in Ubuntu for Android build

To build Android version earlier than Lollipop from source code, you need the Sun's 1.6 SDK to be installed for ubuntu as the link Initializing a Build Environment | Android Developers.

You may still cannot get the Sun's JDK  with below instruction:

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt
-get update
$ sudo apt
-get install sun-java6-jdk

  

There are below options to help install the Sun's JDK  if you cannot find a valid source through apt-get commands:

$ wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin

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

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

$ sudo mv jdk1.6.0_45 /opt

$ sudo update-alternatives --install /usr/bin/java java /opt/java/64/jdk1.6.0_45/bin/java 1

$ sudo update-alternatives --install /usr/bin/javac javac /opt/java/64/jdk1.6.0_45/bin/javac 1

$ sudo update-alternatives --install /usr/bin/jar jar /opt/java/64/jdk1.6.0_45/bin/jar 1

# if you have already install some other version of JDK, please export the JAVA_HOME env before your android build every time

$ export JAVA_HOME=/opt/jdk1.6.0_45/

#or you can directly link the java binary to the sdk version you need as below:

sudo ln -s /opt/java/64/jdk1.6.0_45/bin/jar /bin/jar

sudo ln -s/opt/java/64/jdk1.6.0_45/java /bin/java

sudo ln -s/opt/java/64/jdk1.6.0_45/javac /bin/javac
sudo ln -s/opt/java/64/jdk1.6.0_45/javah /bin/javah
sudo ln -s/opt/java/64/jdk1.6.0_45/javadoc /bin/javadoc
sudo ln -s/opt/java/64/jdk1.6.0_45/
javaws /bin/javaws

  

To built the Android version Lollipop and Marshmallow from source code, you need the OpenJDK 7 to be installed for ubuntu as the link Initializing a Build Environment | Android Developers.

$ sudo apt-get update
$ sudo apt-get install openjdk-7-jdk

You may have both openjdk7 and SUN JDK 1.6 intalled in your ubuntu to build different Android version. If you have default java SDK to be Sun's JDK 1.6, you can just use below commands to make android build system use the openjdk7 for Lollipop built

$ export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

$ cd myandroid

$ . ./build/envsetup.sh           //be sure to resetup the envsetup, and pick the platform to be built

$ lunch

Labels (3)
Comments

Thanks for the useful guide.

I had a couple of problems with it, which I will explain here in case it helps anyone else.


1)  sudo mv jdk1.6.0_45 /opt

This seems to put the code in the wrong place. Instead I used:

sudo mkdir -p /opt/java/64

sudo mv jdk1.6.0_45 /opt/java/64

2) sudo ln -s/opt/java/64/jdk1.6.0_45/java /bin/java

There seems to be a space missing so if you just copy/paste these symlink commands they don't work.(The first one is OK, the other 5 fail).

Here are copies with the space added:

sudo ln -s /opt/java/64/jdk1.6.0_45/java /bin/java

sudo ln -s /opt/java/64/jdk1.6.0_45/javac /bin/javac
sudo ln -s /opt/java/64/jdk1.6.0_45/javah /bin/javah
sudo ln -s /opt/java/64/jdk1.6.0_45/javadoc /bin/javadoc
sudo ln -s /opt/java/64/jdk1.6.0_45/
javaws /bin/javaws

All comments welcome! :smileyhappy:

Thanks for sharing! I had the same problems on the directory structure and had to use a similar approach.


I also had to add --no-check-certificate when using wget in order to successfully download the .bin, so the command ended up as follow:

$ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin

Hi,

The easiest way to do this is to go to:

Java Archive Downloads - Java SE 6

Look for "jdk-6u45-linux-x64.bin" and manually download it. You will have to login (or create an account). Once it has finished downloading, I usually will copy the jdk (jdk-6u45-linux-x64.bin) to the home directory.

Then we need to run the binary and move it to a shared location:


$ 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

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

Now 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)

Now the copy of "jdk-6u45-linux-x64.bin" in your home directory can be deleted, and you can save the one you downloaded for future use.

I know this works for Ubuntu 12.04 LTS (Precise) through Ubuntu 14.04 LTS (Trusty).

Hope this helps out.

Best Regards,

Dave

The "deb http://archive.canonical.com/ lucid partner" source doesn't work. Now we can try:

$ sudo add-apt-repository "deb http://ppa.launchpad.net/ferramroberto/java/ubuntu natty main"

$ sudo apt-get update

$ sudo apt-get install sun-java6-jdk

No ratings
Version history
Last update:
‎11-17-2013 10:31 PM
Updated by: