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
- $ sudo apt-get update
- $ sudo apt-get install OPENJDK-7-JDK
Locate the installation path after the installation is complete:
[Plain]View PlainCopy
- $ 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
Second, switch Java version
[Plain]View PlainCopy
- $ sudo update-alternatives--config java
- There is 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 Mode
- Press ENTER to keep the current choice[*], or type selection number:2
- Update-alternatives:using/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to Provide/usr/bin/java (Java) in manual Mode.
- $ java-version
- Java Version "1.7.0_65"
- 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
- $ 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.
Take a look at our config:
[Plain]View PlainCopy
- $ sudo update-alternatives--config java
- There is 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 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 mode
- Press ENTER to keep the current choice[*], or type selection number:1
- 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
- $ java-version
- Java 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 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"