Ubuntu 14.04编译Android源码

经过两天的努力,终于在Ubuntu 14.04下把Andorid源码给编译成功了。抑制住兴奋,写个总结。

首先要下载源码:

在就是要配置java环境,这两天主要是被java环境给坑了。之前在Windows下用惯了jdk7,然后到ubuntu上毫不犹豫地配了1.7的环境,然后各种问题,网上很多地方说需要用jdk6, 然后我就到官网下载jdk6_45(不知为何需要注册登陆),但是在编译过程中还是好多错误,错误都提示到java代码里面了,问公司的大神,说可能是需要jdk6_26 , 无奈之后还是换。终于换到jdk6_26就好了。

配置好jdk的环境变量(可参考Ubuntu安装配置jdk 

还需要添加一下软链接,在编译过程中需要用到

sudo ln -s -f /usr/lib/jvm/jdk1.6/bin/jar

sudo ln -s -f /usr/lib/jvm/jdk1.6/bin/javah

sudo ln -s -f /usr/lib/jvm/jdk1.6/bin/javadoc

再就是需要配置SDK到环境变量,方法如jdk

之后就开始配置Android编译需要的环境,执行下面的脚本:

#!/bin/sh
#########################
# === global config === #
#########################
WORKDIR=`dirname $(readlink -f $0)`

LOGFILE="$WORKDIR/install.log"

URL_HEAD="http://openlinux.amlogic.com:8000"

#########################
#  === function ===    #
#########################

check_root()
{
 if [ "$(id -u)" != "0" ]; then
 echo "!!!! This script must be run as root !!!" 1>&2
 echo "USAGE: please use command: sudo su - change to account root if your account is sudo user" 1>&2
 echo "or use command: su - root change to account root if it's not a sudo user" 1>&2
 echo "Script will exit, you need run it again" 1>&2
 exit 1
 else
 echo "OK.... you are running by root.. system will keep going..."
 fi
}

check_OS()
{
 OS_MACHINE=`uname -m`
 if [ "$OS_MACHINE" = "x86_64" ]; then
 echo "OK~~~your OS is 64bit... you can use this script...."
 else
 echo "Sorry, This script doesn't support your OS platform.... will exit"
 exit 1
 fi
}

change_sourcelist()
{
 echo "Going to check your OS version....."
 OS_NUMBER=`cat /etc/lsb-release  |grep RELEASE |awk -F "=" '{print $2}'`
 if [ "$OS_NUMBER" = "10.10" ]; then
  OS_VERSION="maverick"
 else if [ "$OS_NUMBER" = "11.10" ]; then
  OS_VERSION="oneiric"
 else if [ "$OS_NUMBER" = "12.04" ]; then
  OS_VERSION="precise"
 else if [ "$OS_NUMBER" = "13.10" ]; then
  OS_VERSION="saucy"
 else if [ "$OS_NUMBER" = "14.04" ]; then 
  OS_VERSION="trusty"
 else
  echo "Sorry, This script only support Ubuntu 10.10 and 11.10,12.04..... will exit!!"
  exit 1
 fi
 fi
 fi
 fi
 fi

}
 
install_software()
{
 echo "We are going to do apt-get update..... please wait......"
 apt-get update
 echo "############################################################"
 echo "#####      going to install samba,nfs,vim            #####"
 echo "############################################################"
 apt-get install -y nfs-kernel-server vim autofs automake make perl gcc g++
}
config_software()
{
 

echo "############################################################"
 echo "#####      going to install gnutools, arm gcc        #####"
 echo "############################################################"
 wget $URL_HEAD/deploy/CodeSourcery.tar.gz -P /tmp
 tar -zxvf /tmp/CodeSourcery.tar.gz -C /opt
 wget $URL_HEAD/deploy/gnutools.tar.gz -P /tmp
 tar -zxvf /tmp/gnutools.tar.gz -C /opt
 wget $URL_HEAD/deploy/gcc-linaro-arm-linux-gnueabihf.tar.gz -P /tmp
 tar -zxvf /tmp/gcc-linaro-arm-linux-gnueabihf.tar.gz -C /opt
 wget $URL_HEAD/deploy/arc-4.8-amlogic-20130904-r2.tar.gz  -P /tmp
 tar -zxvf /tmp/arc-4.8-amlogic-20130904-r2.tar.gz -C /opt/gnutools


 wget $URL_HEAD/deploy/arc_gnutools.sh -P /etc/profile.d
 wget $URL_HEAD/deploy/arm_path.sh -P /etc/profile.d
 wget $URL_HEAD/deploy/repo -P /usr/bin
 wget $URL_HEAD/deploy/arm_new_gcc.sh -P /etc/profile.d
 wget $URL_HEAD/deploy/arc_new_tools.sh -P /etc/profile.d

chmod +x /usr/bin/repo

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/cc50f86554d83e1c2e8d6bdee693b844.html