[SG] switch between different versions of Android source code compiling jdk

1. Why do I need to switch?

Android 4.4 source compilation requires Sun (acquired by Oracle) SunJdk1.6. From 5.0, in order to avoid property rights problems, Google turned to JDK open source version OpenJDK1.7. Generally, our compilation server is the same computer, so we need to install multiple versions of JDK and switch during compilation.

2. Install multiple versions of JDK

- JDK1.6

It is recommended to query the installation method corresponding to your own Ubuntu version. For the following script, please refer to

chmod +x jdk-6u43-linux-x64.bin
./jdk-6u43-linux-x64.bin

mkdir -p /usr/lib/jvm
mv jdk1.6.0_43 /usr/lib/jvm

# Update symbolic links for Java
update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.6.0_43/bin/java" 1
update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_43/bin/javac" 1
update-alternatives --install "/usr/bin/javadoc" "javadoc" "/usr/lib/jvm/jdk1.6.0_43/bin/javadoc" 1
update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/usr/lib/jvm/jdk1.6.0_43/jre/lib/amd64/libnpjp2.so" 1
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.6.0_43/bin/javaws" 1
update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.6.0_43/bin/jar" 1
update-alternatives --install "/usr/bin/javap" "javap" "/usr/lib/jvm/jdk1.6.0_43/bin/javap" 1
# Choose the java you installed as default 
update-alternatives --config java
update-alternatives --config javac
update-alternatives --config javadoc
update-alternatives --config mozilla-javaplugin.so
update-alternatives --config javaws
update-alternatives --config jar
update-alternatives --config javap
# Verify installation
java -version
javac -version

- OpenJDK1.7

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

3. switch JDK

Refer to the following script

#!/bin/sh
update-alternatives --config java << EOF
3
EOF
update-alternatives --config javac << EOF
3
EOF
update-alternatives --config javadoc << EOF
2
EOF
update-alternatives --config mozilla-javaplugin.so
update-alternatives --config javaws 
update-alternatives --config jar << EOF
2
EOF
update-alternatives --config javap << EOF
2
EOF

java -version
javac -version

The specific option number can be viewed according to the personal machine

Keywords: jvm Java JDK Linux

Added by penguin_powered on Mon, 23 Mar 2020 17:56:26 +0200