ubuntu12.04/14.04搭建android编译环境

来源:互联网 发布:ps4听歌软件 编辑:程序博客网 时间:2024/06/06 02:07

本文来自linux与嵌入式技术Q群52240781

ubuntu12.04/14.04安装后搭建android编译环境

注安装的是64位ubuntu系统12.04或14.04

请安装ubuntu的LTS版即12.04或14.04(每2年发布一个LTS版),可以得到5年的更新支持,否则一般的版本只有9个月的更新支持

 

1.更新软件仓库和软件升级

点击复制按钮将以下代码复制并保存为sh后缀的shell脚本如ubuntu_embed_env_setup.sh

 然后执行/bin/bash ubuntu_embed_env_setup.sh


#! /bin/bash# Author:longbin <beangr@163.com># Created Date:2014-06-24# Release Version:1.15.805# Last Modified:2015-08-05# this script is available for ubuntu to configure embedded environment#list the software need to be installed to the variable FILELISTBASIC_TOOLS="axel vim vim-gnome vim-doc vim-scripts ctags cscope gawk curl rar unrar zip unzip ghex nautilus-open-terminal p7zip-full tree uml-utilities meld gimp dos2unix unix2dos tofrodos python-markdown subversion filezilla indent "CODE_TOOLS="build-essential git-core gitk libtool cmake automake flex bison gperf graphviz gnupg mingw32 gettext libc6-dev libc++-dev lib32stdc++6 libncurses5-dev lib32bz2-1.0 lib32bz2-dev gcc g++ g++-multilib "EMBED_TOOLS="ckermit minicom putty tftp-hpa tftpd-hpa uml-utilities nfs-kernel-server "BUILD_ANDROID_U12="git gnupg flex bison gperf python-markdown build-essential zip curl ia32-libs libc6-dev libncurses5-dev:i386 xsltproc x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos libxml2-utils zlib1g-dev:i386 "#libgl1-mesa-dri:i386 libgl1-mesa-glx:i386BUILD_ANDROID_U14_ESSENTIAL="git gperf python-markdown g++-multilib libxml2-utils "BUILD_ANDROID_U14_TOOLS="git-core flex bison gperf gnupg build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev lib32z1 x11proto-core-dev libx11-dev libreadline-gplv2-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc libxml-simple-perl"AI_TOOLS="build-dep python python-numpy python-scipy python-setuptools matplotlib"PROXY_TOOLS="ntlmaps"## apt-cache search opencv# OPEN_CV="$(apt-cache search opencv | awk '{print $1}')"# OPEN_CV="libgtk2.0-dev pkg-config"## g++ `pkg-config opencv --cflags --libs` my_example.cpp -o my_example## bison and flex is the analyzer of programmer and spell## textinfo is a tool to read manual like man## automake is used to help create Makefile## libtool helps to deal with the dependency of libraries## cvs, cvsd and subversion are used to control version## ubuntu 12.04 software installing listU1204_FILELIST="${BASIC_TOOLS} ${CODE_TOOLS} ${EMBED_TOOLS} \${BUILD_ANDROID_U12}"## ubuntu 14.04 software installing listU1404_FILELIST="${BASIC_TOOLS} ${CODE_TOOLS} ${EMBED_TOOLS} \${BUILD_ANDROID_U14_ESSENTIAL} \${BUILD_ANDROID_U14_TOOLS}"INSTALL_CHECK_FLAG="-y"## check_user_UIDfunction check_user_UID() {#if [[ ${UID} -lt 1000 ]] ;then#echo "ERROR: Please don't use root to execute this script."#exit 1#fisudo ls > /dev/nullif [[ "x$?" == "x1" ]] ;thenecho -e "\tThere is a configuration/permission problem."echo -e "\tPlease ensure that you have permission to use sudo"exit 1fiif [ "x${UID}" == "x0" ] ;thenSUDO=''elseSUDO=sudofi}## check whether system is Ubuntu or notfunction check_system_distributor() {## get system distributor ID: Ubuntu ?LINUX_DISTRIBUTOR=$(cat /etc/issue |tr 'A-Z' 'a-z'|awk ' /release/ {print $1}' | sed -n "1p")LINUX_DISTRIBUTOR=${LINUX_DISTRIBUTOR:=$(lsb_release -i |tr 'A-Z' 'a-z'|awk '/distributor/ {print $3}')}LINUX_DISTRIBUTOR=${LINUX_DISTRIBUTOR:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/\<release\>/ {print $1}'|sed -n '1p')}LINUX_DISTRIBUTOR=${LINUX_DISTRIBUTOR:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/distrib_id=/ {print $1}'|sed 's/distrib_id=//'|sed -n '1p')}echo "checking system distributor and release ID ..."if [[ "${LINUX_DISTRIBUTOR}" == "ubuntu" ]] ;thenecho -e "\tCurrent OS Distributor: ${LINUX_DISTRIBUTOR}"elseecho -e "\tCurrent OS is not ubuntu"echo -e "\tCurrent OS Distributor: ${LINUX_DISTRIBUTOR}"exit 1fi}## check whether system is Ubuntu 12.04 or 14.04function check_system_release_version() {## get system release version: 12.04/14.04 ?LINUX_RELEASE_VERSION=$(cat /etc/issue | awk '/release/ {print $3}'| sed -n '1p')LINUX_RELEASE_VERSION=${LINUX_RELEASE_VERSION:=$(lsb_release -r | tr 'A-Z' 'a-z' | awk '/release/ {print $2}')}LINUX_RELEASE_VERSION=${LINUX_RELEASE_VERSION:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/\<release\>/ {print $3}'|sed -n '1p')}LINUX_RELEASE_VERSION=${LINUX_RELEASE_VERSION:=$(cat /etc/*release |tr 'A-Z' 'a-z'|awk '/distrib_release=/ {print $1}'|sed 's/distrib_release=//'|sed -n '1p')}case ${LINUX_RELEASE_VERSION:0:5} in12.04)echo -e "\tCurrent OS Version: ${LINUX_RELEASE_VERSION}"FILELIST=${U1204_FILELIST};;14.04|16.04|18.04)echo -e "\tCurrent OS Version: ${LINUX_RELEASE_VERSION}"FILELIST=${U1404_FILELIST};;*)echo "Only support Ubuntu LTS version, eg: 12.04/14.04 ..."exit 1;;esac# sleep 2}## check linux system environmentfunction check_linux_system_env() {check_system_distributorcheck_system_release_versioncheck_user_UIDecho "checked OK, preparing to setup softwares ..."}## update and upgrade systemfunction update_upgrade_ubuntu() {read -p "    update software source.list <y/N>? " selectif [[ "x${select}" == "xy" ]] ;thenecho "sudo apt-get update"#update the source.list${SUDO} apt-get updatefiread -p "    upgrade system <y/N>? " selectif [[ "x${select}" == "xy" ]] ;thenecho "sudo apt-get upgrade"#upgrade the software have installed on the system${SUDO} apt-get upgradefi}## function initial vimfunction vim_initialize_viminfo() {if [[ "${UID}" -ge 1000 ]] ;thenlocal VIMINFO_HOME=${HOME}echo "initializing viminfo file ..."${SUDO} rm -f ${VIMINFO_HOME}/.viminfo# touch ${VIMINFO_HOME}/.viminfofi}#install one software every cyclefunction install_soft_for_each() {trap 'echo -e "\nAborted by user, exit";exit' INTecho "Will install below software for your system:"local soft_num=0local cur_num=0for file in ${FILELIST}dolet soft_num+=1echo -e "${file} \c"doneecho ""TMOUT=10read -p "    Install above softwares <Y/n>? " selectif [[ "x${select}" == "xn" ]] ;thenreturnfi# FILELIST=$(echo ${FILELIST} | sed 's/[\t ]/\n/g'| sort -u)for file in ${FILELIST}dolet cur_num+=1let cur_percent=cur_num*100/soft_num# echo "${cur_percent}%"echo "========================="echo " [${cur_percent}%] installing $file ..."echo "-------------------------"${SUDO} apt-get install ${file} ${INSTALL_CHECK_FLAG}# sleep 1echo "$file installed ."donevim_initialize_viminfo}function create_link_mesa_libGL_so() {LIB_GL_SO=/usr/lib/i386-linux-gnu/libGL.soLIB_GL_SO_1=/usr/lib/i386-linux-gnu/mesa/libGL.so.1if ! [[ -f "${LIB_GL_SO_1}" ]] ;thenreturnfi${SUDO} ln -s -f ${LIB_GL_SO_1} ${LIB_GL_SO}}## install ibus input method framefunction install_ibus_pinyin_for_ubuntu(){read -p "press <Enter> to install and setup ibus-pinyin "${SUDO} apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4 -y## install ibus pinyin${SUDO} apt-get install ibus-pinyin -ysleep 3read -p "Press <Enter> to select ibus-pinyin as the defalut input method "im-config## restart ibus-pinyin##try below command to repair ibus-pinyin:#ibus-daemon -drxibus-daemon -drxif [[ -f ~/.bashrc ]] ;thenlocal IS_EXIST=$(cat ~/.bashrc | sed -n '/ibus-daemon/p')if [[ "${IS_EXIST}" == "" ]] ;thencp ~/.bashrc ~/.bashrc_$(date +%Y%m%d_%H%M%S)echo "ibus-daemon -drx" >> ~/.bashrcfifi## ibus-setup## add ibus-pinyin input method to the input method listread -p "Press <Enter> to select and add ibus-pinyin "ibus-setup## configure ibus pinyinif [[ "${LINUX_RELEASE_VERSION}" == "12.04" ]] ;then/usr/lib/ibus-pinyin/ibus-setup-pinyinelif [[ "${LINUX_RELEASE_VERSION}" == "14.04" ]] ;then/usr/lib/ibus/ibus-setup-pinyinfiecho "====================================================="echo -e "\tSetup ibus input method OK, please re-login your system and execute below commands to configure it. "echo -e "\t\t/usr/lib/ibus-pinyin/ibus-setup-pinyin #for ubuntu1204"echo -e "\t\t/usr/lib/ibus/ibus-setup-pinyin #for ubuntu1404 or later version"echo "====================================================="}function remove_ibus_pinyin_from_ubuntu() {## remove ibus-pinyin will lead some problems, repair our OS by below command:## ${SUDO} apt-get install ibus-pinyin unity-control-center \## unity-control-center-signon webaccounts-extension-common xul-ext-webaccounts## remove ibus-pinyinread -p "Press <Enter> to remove ibus "${SUDO} apt-get purge ibus${SUDO} apt-get autoremove## repair OS when removed ibus pinyin ${SUDO} apt-get install unity-control-center unity-control-center-signon webaccounts-extension-common xul-ext-webaccounts}function install_fcitx_pinyin_for_ubuntu() {remove_ibus_pinyin_from_ubuntu## install fcitx pinyinecho "installing fcitx ..."${SUDO} apt-get install fcitx fcitx-pinyinread -p "Press <Enter> to select your input method [fcitx] "im-configread -p "Press <Enter> to add your input method [pinyin] "fcitx-config-gtk3echo "====================================================="echo -e "\tSetup fcitx input method OK, please re-login your system and execute below commands to configure it. "echo -e "\t\tim-config"echo -e "\t\tfcitx-config-gtk3"echo "====================================================="}function countdown_select_for_each() {#################################local DEFAULT_OPTION=local TIME_SELECT_TIMEOUT=9local PROMTE_MESSAGE_HEADER="$1"local PROMTE_MESSAGE_TAIL=" in ${TIME_SELECT_TIMEOUT}s: "##################################################################local OPTIONS=$(echo 'This_is_your_OPTIONS')#################################local PROMTE_MESSAGES=${PROMTE_MESSAGE_HEADER:="Please select"}${PROMTE_MESSAGE_TAIL}echo "Will use a default value if you choosed none in ${TIME_SELECT_TIMEOUT}s. "for ((countdown=${TIME_SELECT_TIMEOUT}-1; countdown>=1; countdown--)) dotrap 'exit 0' HUPsleep 1; echo -e "\r${PROMTE_MESSAGE_HEADER} in ${countdown}s: \c"done &local BG_PID=$!local TMOUT=${TIME_SELECT_TIMEOUT}local option=${DEFAULT_OPTION}PS3="${PROMTE_MESSAGES}"trap 'kill ${BG_PID}; echo; exit' INTselect option in "ibus-pinyin" "fcitx-pinyin" "Use default input method"doif [[ "x${option}" != "x" ]] ;thenbreakelseecho "Invalid option, try again."fidone(kill -HUP ${BG_PID} &>/dev/null)echoif [[ "x${option}" != "x" ]] ;thenecho "You select: ${option}"elseecho "You select none."fitrap 'exit' INT}function install_ibus_or_fcitx_pinyin() {REPLY=countdown_select_for_each  "Please select your input method"case ${REPLY} in1)echo "Preparing install_ibus_pinyin_for_ubuntu ..."install_ibus_pinyin_for_ubuntu;;2)echo "Preparing install_fcitx_pinyin_for_ubuntu ..."install_fcitx_pinyin_for_ubuntu;;*)echo "Use default input method. ";;esac}function install_ubuntu_multimedia_supports() {TMOUT=read -p "    Install multimedia libs <y/N>? " selectif [[ "${select}" == "y" ]] ;thenecho "This will take you a long time to download."${SUDO} apt-get install ubuntu-restricted-addons${SUDO} apt-get install ubuntu-restricted-extraselsereturnfi}read -p "Setup build environment for ubuntu 12.04/14.04, press <Enter> to continue "check_linux_system_envupdate_upgrade_ubuntuinstall_soft_for_eachcreate_link_mesa_libGL_soinstall_ibus_or_fcitx_pinyininstall_ubuntu_multimedia_supportsecho "Finished !"



2.根据编译安卓的需要安装对应版本的java环境

Adnroid L要求用openjdk,

Android L之前的版本要求使用sunjdk

 

0 0