Practical Android skills: Switch JDK under Ubuntu

Source: Internet
Author: User

Practical Android skills: Switch JDK under Ubuntu

After Android L, we recommend that you use JDK 7 to compile the program. This is a natural development rule, just like compiling Android 1.6 4 years ago and using JDK 5.

Multi-version JDK can coexist. You only need to use the update-alternatives tool to switch between them at any time. The following describes how to install openjdk and oracle jdk (cannot cope with sun) and switch the version.

1. Install openjdk7
$ sudo apt-get update$ sudo apt-get install openjdk-7-jdk
Find the installation path after installation:
$ dpkg -L openjdk-7-jdk/./usr/usr/lib/usr/lib/jvm/usr/lib/jvm/java-7-openjdk-amd64$ ls /usr/lib/jvm/java-7-openjdk-amd64/ASSEMBLY_EXCEPTION  bin  docs  include  jre  lib  man  src.zip  THIRD_PARTY_README
Ii. Switch java version
$ sudo update-alternatives --config javaThere are 2 choices for the alternative java (providing /usr/bin/java).  Selection    Path                                            Priority   Status------------------------------------------------------------* 0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual modePress enter to keep the current choice[*], or type selection number: 2update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode.$ java -versionjava version "1.7.0_65"OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.12.04.1)
3. Install the Oracle jdk and use Android Studio for development. When you start the IDE, the following message is displayed:
OpenJDK shows intermittent performance and UI issues. We recommend using the Oracle JRE/JDK.
It seems that the JDK of Oracle is still to be installed, because the JDK is not available in the ubuntu software source, so you cannot use the apt-get tool like installing openjdk.
We still need to download JDK 7 from the official website.

In the past, I put these software under the/opt directory. Decompress JDK to the new directory jdk.
Use the update-alternatives tool to add java optional configuration items (this is a dpkg utility ).
$ sudo update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.7.0_71/bin/java 700$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.7.0_71/bin/javac 700$ sudo update-alternatives --install /usr/bin/jar jar /opt/jdk/jdk1.7.0_71/bin/jar 700
700 is the priority value. I use a random number here.
Check our config:
$ sudo update-alternatives --config javaThere are 3 choices for the alternative java (providing /usr/bin/java).  Selection    Path                                            Priority   Status------------------------------------------------------------  0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode  1            /opt/jdk/jdk1.7.0_71/bin/java                    700       manual mode  2            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode* 3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual modePress enter to keep the current choice[*], or type selection number: 1update-alternatives: using /opt/jdk/jdk1.7.0_71/bin/java to provide /usr/bin/java (java) in manual mode

Verify whether the switchover is successful:

$ java -versionjava version "1.7.0_71"Java(TM) SE Runtime Environment (build 1.7.0_71-b14)Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Similarly, when we need to switch to a lower version, select 2 or install oracle JDK 6 and manage it. In this way, you do not need to manually modify the environment to flexibly switch the JDK version.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.