1.Download JDK 1.6
由于Android使用的是sun/oracle jdk1.6,所以需要下载对应的jdk。现提供一个下载地址如下:http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html
2.Install JDK 1.6
1. mkdir opt/java
2. copy jdk-6u45-linux-x64.bin to /opt/java
3. cd /opt
chmod a+x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
4.set oracle jdk1.6 environment to /etc/bash.bashrc
export JAVA_HOME=/opt/java/jdk1.6.0_45
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME/lib:$JAVA_HOME
5.source /etc/bash.bashrc
3.Install JDK1.7
1.sudo apt-get -y install openjdk-7-jdk
2.update-java-alternatives -s java-1.7.0-openjdk-amd64
注:由于设置环境变量已经放在了脚本里面,所以第四步需要去掉。
4.执行脚本bjdk
附:bjdk
#!/bin/bash
sudo update-alternatives --install /usr/bin/javah javah /opt/java/jdk1.6.0_45/bin/javah 255
sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk1.6.0_45/bin/javac 255
sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.6.0_45/bin/java 255
sudo update-alternatives --install /usr/bin/jar jar /opt/java/jdk1.6.0_45/bin/jar 255
sudo update-alternatives --install /usr/bin/javap javap /opt/java/jdk1.6.0_45/bin/javap 255
sudo update-alternatives --install /usr/bin/jps jps /opt/java/jdk1.6.0_45/bin/jps 255
sudo update-alternatives --install /usr/bin/jconsole jconsole /opt/java/jdk1.6.0_45/bin/jconsole 255
sudo update-alternatives --install /usr/bin/javadoc javadoc /opt/java/jdk1.6.0_45/bin/javadoc 255
sudo update-alternatives --install /usr/bin/appletviewer appletviewer /opt/java/jdk1.6.0_45/bin/appletviewer 255
sudo update-alternatives --install /usr/bin/apt apt /opt/java/jdk1.6.0_45/bin/apt 255
sudo update-alternatives --install /usr/bin/extcheck extcheck /opt/java/jdk1.6.0_45/bin/extcheck 255
sudo update-alternatives --install /usr/bin/idlj idlj /opt/java/jdk1.6.0_45/bin/idlj 255
sudo update-alternatives --install /usr/bin/jarsigner jarsigner /opt/java/jdk1.6.0_45/bin/jarsigner 255
sudo update-alternatives --install /usr/bin/jdb jdb /opt/java/jdk1.6.0_45/bin/jdb 255
sudo update-alternatives --install /usr/bin/javaws javaws /opt/java/jdk1.6.0_45/bin/javaws 255
sudo update-alternatives --install /usr/bin/jhat jhat /opt/java/jdk1.6.0_45/bin/jhat 255
sudo update-alternatives --install /usr/bin/jinfo jinfo /opt/java/jdk1.6.0_45/bin/jinfo 255
sudo update-alternatives --install /usr/bin/jmap jmap /opt/java/jdk1.6.0_45/bin/jmap 255
sudo update-alternatives --install /usr/bin/jrunscript jrunscript /opt/java/jdk1.6.0_45/bin/jrunscript 255
sudo update-alternatives --install /usr/bin/jsadebugd jsadebugd /opt/java/jdk1.6.0_45/bin/jsadebugd 255
sudo update-alternatives --install /usr/bin/jstack jstack /opt/java/jdk1.6.0_45/bin/jstack 255
sudo update-alternatives --install /usr/bin/jstat jstat /opt/java/jdk1.6.0_45/bin/jstat 255
sudo update-alternatives --install /usr/bin/jstatd jstatd /opt/java/jdk1.6.0_45/bin/jstatd 255
sudo update-alternatives --install /usr/bin/keytool keytool /opt/java/jdk1.6.0_45/bin/keytool 255
sudo update-alternatives --install /usr/bin/native2ascii native2ascii /opt/java/jdk1.6.0_45/bin/native2ascii 255
sudo update-alternatives --install /usr/bin/orbd orbd /opt/java/jdk1.6.0_45/bin/orbd 255
sudo update-alternatives --install /usr/bin/pack200 pack200 /opt/java/jdk1.6.0_45/bin/pack200 255
sudo update-alternatives --install /usr/bin/policytool policytool /opt/java/jdk1.6.0_45/bin/policytool 255
sudo update-alternatives --install /usr/bin/rmic rmic /opt/java/jdk1.6.0_45/bin/rmic 255
sudo update-alternatives --install /usr/bin/rmid rmid /opt/java/jdk1.6.0_45/bin/rmid 255
sudo update-alternatives --install /usr/bin/rmiregistry rmiregistry /opt/java/jdk1.6.0_45/bin/rmiregistry 255
sudo update-alternatives --install /usr/bin/schemagen schemagen /opt/java/jdk1.6.0_45/bin/schemagen 255
sudo update-alternatives --install /usr/bin/serialver serialver /opt/java/jdk1.6.0_45/bin/serialver 255
sudo update-alternatives --install /usr/bin/servertool servertool /opt/java/jdk1.6.0_45/bin/servertool 255
sudo update-alternatives --install /usr/bin/tnameserv tnameserv /opt/java/jdk1.6.0_45/bin/tnameserv 255
sudo update-alternatives --install /usr/bin/unpack200 unpack200 /opt/java/jdk1.6.0_45/bin/unpack200 255
sudo update-alternatives --install /usr/bin/wsgen wsgen /opt/java/jdk1.6.0_45/bin/wsgen 255
sudo update-alternatives --install /usr/bin/wsimport wsimport /opt/java/jdk1.6.0_45/bin/wsimport 255
sudo update-alternatives --install /usr/bin/xjc xjc /opt/java/jdk1.6.0_45/bin/xjc 255
5.gcc的安装
1.sudo apt-get install gcc-4.4 gcc-4.4-multilib g++-4.4 g++-4.4-multilib
2.sudo apt-get install gcc-4.6 gcc-4.6-multilib g++-4.6 g++-4.6-multilib
3.执行脚本bgcc
注:由于android4.4使用gcc4.4,android5.1使用gcc4.6,所以两个都需安装。
附:bgcc
#!/bin/bash
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 60
6.提供两个脚本:使用之前请根据需要赋予执行权限并执行对应的脚本
附:jdk1.6.sh
export JAVA_HOME=/opt/java/jdk1.6.0_45
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME/lib:$JAVA_HOME
echo 1 | sudo update-alternatives --config java
echo -e '\n'
echo 1 | sudo update-alternatives --config javac
echo -e '\n'
echo 1 | sudo update-alternatives --config javah
echo -e '\n'
echo 1 | sudo update-alternatives --config jar
echo -e '\n'
echo 1 | sudo update-alternatives --config javap
echo -e '\n'
echo 1 | sudo update-alternatives --config jps
echo -e '\n'
echo 1 | sudo update-alternatives --config jconsole
echo -e '\n'
echo 1 | sudo update-alternatives --config javadoc
echo -e '\n'
echo 1 | sudo update-alternatives --config appletviewer
echo -e '\n'
echo 1 | sudo update-alternatives --config apt
echo -e '\n'
echo 1 | sudo update-alternatives --config extcheck
echo -e '\n'
echo 1 | sudo update-alternatives --config idlj
echo -e '\n'
echo 1 | sudo update-alternatives --config jarsigner
echo -e '\n'
echo 1 | sudo update-alternatives --config jdb
echo -e '\n'
echo 1 | sudo update-alternatives --config javaws
echo -e '\n'
echo 1 | sudo update-alternatives --config jhat
echo -e '\n'
echo 1 | sudo update-alternatives --config jinfo
echo -e '\n'
echo 1 | sudo update-alternatives --config jmap
echo -e '\n'
echo 1 | sudo update-alternatives --config jrunscript
echo -e '\n'
echo 1 | sudo update-alternatives --config jsadebugd
echo -e '\n'
echo 1 | sudo update-alternatives --config jstack
echo -e '\n'
echo 1 | sudo update-alternatives --config jstat
echo -e '\n'
echo 1 | sudo update-alternatives --config jstatd
echo -e '\n'
echo 1 | sudo update-alternatives --config keytool
echo -e '\n'
echo 1 | sudo update-alternatives --config native2ascii
echo -e '\n'
echo 1 | sudo update-alternatives --config orbd
echo -e '\n'
echo 1 | sudo update-alternatives --config pack200
echo -e '\n'
echo 1 | sudo update-alternatives --config policytool
echo -e '\n'
echo 1 | sudo update-alternatives --config rmic
echo -e '\n'
echo 1 | sudo update-alternatives --config rmid
echo -e '\n'
echo 1 | sudo update-alternatives --config rmiregistry
echo -e '\n'
echo 1 | sudo update-alternatives --config schemagen
echo -e '\n'
echo 1 | sudo update-alternatives --config serialver
echo -e '\n'
echo 1 | sudo update-alternatives --config servertool
echo -e '\n'
echo 1 | sudo update-alternatives --config tnameserv
echo -e '\n'
echo 1 | sudo update-alternatives --config unpack200
echo -e '\n'
echo 1 | sudo update-alternatives --config wsgen
echo -e '\n'
echo 1 | sudo update-alternatives --config wsimport
echo -e '\n'
echo 1 | sudo update-alternatives --config xjc
echo -e '\n'
echo 1 | sudo update-alternatives --config gcc
echo -e '\n'
echo 1 | sudo update-alternatives --config g++
echo -e '\n'
附:jdk1.7.sh
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME/lib:$JAVA_HOME
echo 2 | sudo update-alternatives --config java
echo -e '\n'
echo 2 | sudo update-alternatives --config javac
echo -e '\n'
echo 2 | sudo update-alternatives --config javah
echo -e '\n'
echo 2 | sudo update-alternatives --config jar
echo -e '\n'
echo 2 | sudo update-alternatives --config javap
echo -e '\n'
echo 2 | sudo update-alternatives --config jps
echo -e '\n'
echo 2 | sudo update-alternatives --config jconsole
echo -e '\n'
echo 2 | sudo update-alternatives --config javadoc
echo -e '\n'
echo 2 | sudo update-alternatives --config appletviewer
echo -e '\n'
echo 2 | sudo update-alternatives --config apt
echo -e '\n'
echo 2 | sudo update-alternatives --config extcheck
echo -e '\n'
echo 2 | sudo update-alternatives --config idlj
echo -e '\n'
echo 2 | sudo update-alternatives --config jarsigner
echo -e '\n'
echo 2 | sudo update-alternatives --config jdb
echo -e '\n'
echo 2 | sudo update-alternatives --config javaws
echo -e '\n'
echo 2 | sudo update-alternatives --config jhat
echo -e '\n'
echo 2 | sudo update-alternatives --config jinfo
echo -e '\n'
echo 2 | sudo update-alternatives --config jmap
echo -e '\n'
echo 2 | sudo update-alternatives --config jrunscript
echo -e '\n'
echo 2 | sudo update-alternatives --config jsadebugd
echo -e '\n'
echo 2 | sudo update-alternatives --config jstack
echo -e '\n'
echo 2 | sudo update-alternatives --config jstat
echo -e '\n'
echo 2 | sudo update-alternatives --config jstatd
echo -e '\n'
echo 2 | sudo update-alternatives --config keytool
echo -e '\n'
echo 2 | sudo update-alternatives --config native2ascii
echo -e '\n'
echo 2 | sudo update-alternatives --config orbd
echo -e '\n'
echo 2 | sudo update-alternatives --config pack200
echo -e '\n'
echo 2 | sudo update-alternatives --config policytool
echo -e '\n'
echo 2 | sudo update-alternatives --config rmic
echo -e '\n'
echo 2 | sudo update-alternatives --config rmid
echo -e '\n'
echo 2 | sudo update-alternatives --config rmiregistry
echo -e '\n'
echo 2 | sudo update-alternatives --config schemagen
echo -e '\n'
echo 2 | sudo update-alternatives --config serialver
echo -e '\n'
echo 2 | sudo update-alternatives --config servertool
echo -e '\n'
echo 2 | sudo update-alternatives --config tnameserv
echo -e '\n'
echo 2 | sudo update-alternatives --config unpack200
echo -e '\n'
echo 2 | sudo update-alternatives --config wsgen
echo -e '\n'
echo 2 | sudo update-alternatives --config wsimport
echo -e '\n'
echo 2 | sudo update-alternatives --config xjc
echo -e '\n'
echo 2 | sudo update-alternatives --config gcc
echo -e '\n'
echo 2 | sudo update-alternatives --config g++
echo -e '\n'