猿最近在Ubuntu 14.04.5環(huán)境下搞Android代碼編譯,但是由于重復(fù)開窗口逸爵、切換分支、切換JDK版本凹嘲,要重復(fù)敲很多命令师倔。深感不便,于是自己參考網(wǎng)上的語法周蹭,寫了個(gè)簡單腳本趋艘,現(xiàn)在share給大家,希望大家喜歡(*@ο@*) 哇~凶朗。
1. 總?cè)肟赽uild.sh
#!bin/sh
echo -e "#### open target folder ####\n 1.branch1\n 2.branch2\n 3.branch3\n 4.branch4\n"
echo -n "### input the type:"
read target
case "$target" in
1)
echo -e "\033[1;32m build target is branch1 \033[0m"
. /home/user/script/build_branch1_script.sh
;;
2)
echo -e "\033[1;32m build target is branch2 \033[0m"
. /home/user/script/build_branch2_script.sh
;;
3)
echo -e "\033[1;32m build target is branch3 \033[0m"
. /home/user/script/build_branch3_script.sh
;;
4)
echo -e "\033[1;32m build target is branch4 \033[0m"
. /home/user/script/build_branch4_script.sh
;;
*)
echo -e "\033[1;31m build target is wrong \033[0m"
;;
esac
2. 編譯branch1版本腳本:build_branch1_script.sh
#!bin/sh
echo "### open target folder ###"
cd /home/user/src/android-branch1-dev
echo -e "#### change java environment ####"
sudo sed -ri 's#^.*JAVA_HOME=.*$#export JAVA_HOME=/usr/lib/java/jdk1.6.0_41#' /etc/profile
echo -e "#### source the profile"
. /etc/profile
echo -e "#### output java version"
java -version
echo "### source envsetup.sh ###"
. build/envsetup.sh
echo "### lunch source file ###"
lunch branch1-userdebug
3. 編譯branch2版本腳本:build_branch2_script.sh
#!bin/sh
echo -e "#### open target folder ####"
cd /home/user/src/android-branch2-dev
echo -e "#### change java environment ####"
sudo sed -ri 's#^.*JAVA_HOME=.*$#export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64#' /etc/profile
echo -e "#### source the profile"
. /etc/profile
echo -e "#### output java version"
java -version
echo -e "#### source envsetup.sh ####"
. build/envsetup.sh
echo -e "#### lunch source file ####"
lunch branch2-userdebug
4. 編譯branch3版本腳本:build_branch3_script.sh
#!bin/sh
echo "##### open target folder #####"
cd /home/user/src/android-branch3-dev
echo -e "#### change java environment ####"
sudo sed -ri 's#^.*JAVA_HOME=.*$#export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64#' /etc/profile
echo -e "#### source the profile"
. /etc/profile
echo -e "#### output java version"
java -version
echo "##### source envsetup.sh #####"
. build/envsetup.sh
echo "##### lunch source file #####"
lunch branch3-userdebug
5. 編譯branch4版本腳本:build_branch4_script.sh
#!bin/sh
echo "##### open target folder #####"
cd /home/user/src/android-branch4-dev
echo -e "#### change java environment ####"
sudo sed -ri 's#^.*JAVA_HOME=.*$#export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64#' /etc/profile
echo -e "#### source the profile"
. /etc/profile
echo -e "#### output java version"
java -version
echo "##### source envsetup.sh #####"
. build/envsetup.sh
echo "##### lunch source file #####"
lunch branch4-userdebug
這幾段腳本組合起來的作用其實(shí)特別簡單瓷胧,就是打開對(duì)應(yīng)的分支目錄,同時(shí)修改JAVA_HOME的配置棚愤,啟動(dòng)Android編譯搓萧。當(dāng)然有不少同學(xué)會(huì)說Ubuntu切換JDK可以使用update-alternatives進(jìn)行切換。但是這里本猿要說明一下宛畦,這個(gè)命令配置也挺繁瑣的瘸洛,而且猿配置了以后,發(fā)現(xiàn)切換了使用java -version輸出的一直是默認(rèn)版本次和,切換不過來╮(╯▽╰)╭反肋,后來就放棄了,改用最熟悉的手動(dòng)切換斯够,而且現(xiàn)在配合自己的腳本囚玫,用的還挺順手。當(dāng)然读规,如果有人對(duì)于Ubuntu的java多版本切換有心得或者對(duì)于腳本的改進(jìn)和書寫有什么建議抓督,都可以給猿留言哦~O(∩_∩)O哈哈~