Android combat Skills Eight: Ubuntu under switch jdk version "Go"

Source: Internet
Author: User

This article was reproduced from: http://blog.csdn.net/lincyang/article/details/42024565

Android L recommended using the JDK7 compiler, which is the natural evolution of the law, just like 4 years ago to compile Android 1.6 needs to use JDK5.

Multiple versions of the JDK can coexist, and you can switch them at any time using the Update-alternatives tool. The procedures for installing OPENJDK and Oracle JDK (Sun) and switching versions are described below.

First, install the OPENJDK7 [Plain]View PlainCopy
    1. $ sudo apt-get update
    2. $ sudo apt-get install OPENJDK-7-JDK

Locate the installation path after the installation is complete:

[Plain]View PlainCopy
    1. $ dpkg-l OPENJDK-7-JDK
    2. /.
    3. /usr
    4. /usr/lib
    5. /usr/lib/jvm
    6. /usr/lib/jvm/java-7-openjdk-amd64
    7. $ ls/usr/lib/jvm/java-7-openjdk-amd64/
    8. Assembly_exception bin docs include Jre Lib man src.zip Third_party_readme
Second, switch Java version [Plain]View PlainCopy
  1. $ sudo update-alternatives--config java
  2. There is 2 choices for the alternative Java (Providing/usr/bin/java).
  3. Selection Path Priority Status
  4. ------------------------------------------------------------
  5. * 0/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 Auto mode
  6. 1/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 Manual Mode
  7. 2/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 Manual Mode
  8. Press ENTER to keep the current choice[*], or type selection number:2
  9. Update-alternatives:using/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to Provide/usr/bin/java (Java) in manual Mode.
  10. $ java-version
  11. Java Version "1.7.0_65"
  12. OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.12.04.1)
Third, install Oracle JDK

Using Android Studio for development, starting the IDE prompts you:
OpenJDK shows intermittent performance and UI issues. We recommend using the Oracle jre/jdk.
It appears that you want to install the Oracle JDK, because the Ubuntu software source does not have this JDK, so you cannot use the Apt-get tool as you would install OPENJDK.
Then we still have to go to the official website to download jdk7.

As usual, I put the software in the/OPT directory. Unzip the JDK to the new directory JDK.
Use the Update-alternatives tool to add Java optional configuration items (this is a dpkg utility).

[Plain]View PlainCopy
    1. $ sudo update-alternatives--install/usr/bin/java Java/opt/jdk/jdk1.7.0_71/bin/java 700
    2. $ sudo update-alternatives--install/usr/bin/javac Javac/opt/jdk/jdk1.7.0_71/bin/javac 700
    3. $ 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.
Take a look at our config:

[Plain]View PlainCopy
  1. $ sudo update-alternatives--config java
  2. There is 3 choices for the alternative Java (Providing/usr/bin/java).
  3. Selection Path Priority Status
  4. ------------------------------------------------------------
  5. 0/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 Auto Mode
  6. 1/opt/jdk/jdk1.7.0_71/bin/java Manual Mode
  7. 2/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 Manual Mode
  8. * 3/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 Manual mode
  9. Press ENTER to keep the current choice[*], or type selection number:1
  10. Update-alternatives:using/opt/jdk/jdk1.7.0_71/bin/java to Provide/usr/bin/java (Java) in manual mode

Verify that the switch was successful:

[Plain]View PlainCopy
    1. $ java-version
    2. Java Version "1.7.0_71"
    3. Java (TM) SE Runtime Environment (build 1.7.0_71-b14)
    4. Java HotSpot (TM) 64-bit Server VM (build 24.71-b01, Mixed mode)


Similarly, when we need to switch to the lower version select 2 or install Oracle JDK6 and incorporate it into management. This allows you to flexibly switch the JDK version without having to manually modify the environment.

Android combat Skills Eight: Ubuntu under switch jdk version "Go"

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.