1.首先替换源为163的源,默认源下载速度太慢
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup (备份下当前的源列表)
sudo gedit /etc/apt/sources.list (打开Ubuntu 12.04源列表文件)
deb http://mirrors.163.com/ubuntu/ precise main restricted
deb-src http://mirrors.163.com/ubuntu/ precise main restricted
deb http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb http://mirrors.163.com/ubuntu/ precise universe
deb-src http://mirrors.163.com/ubuntu/ precise universe
deb http://mirrors.163.com/ubuntu/ precise-updates universe
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe
deb http://mirrors.163.com/ubuntu/ precise multiverse
deb-src http://mirrors.163.com/ubuntu/ precise multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ precise-security main restricted
deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted
deb http://mirrors.163.com/ubuntu/ precise-security universe
deb-src http://mirrors.163.com/ubuntu/ precise-security universe
deb http://mirrors.163.com/ubuntu/ precise-security multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-security multiverse
deb http://extras.ubuntu.com/ubuntu precise main
deb-src http://extras.ubuntu.com/ubuntu precise main
#这个源也要添加进去,否则后续安装有些软件时会提示找不到
deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
sudo apt-get update 最后调用这个进行更新源
2.编译环境配置
sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev \
libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 g++-multilib \
mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 libgl1-mesa-dev \
libgl1-mesa-glx:i386
ps:
如果第一步里后面3个源没有添加,则这步libgl1-mesa-glx:i386会提示找不到,然后推荐安装libgl1-mesa-dri:i386,如果安装了这个最终会导致ubuntu起不来了,当然安全模式下还是可以进去
如果加了源还是下不了的话,
下载完后如执行 dpkg -i libgl1-mesa-glx_8.0.4-0ubuntu0.6_i386
最后执行
ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linuxgnu/libGL.so
3.安装java环境
点击上面的链接,下载 Java SE Development Kit 6u45下面的 Linux x64--> jdk-6u45-linux-x64.bin
然后执行下面的命令
mkdir /opt/java
#jdk-6u45-linux-x64.bin需要拷贝到虚拟机里,可以通过samba或者虚拟机自带的共享目录(/mnt/hgfs)
cp jdk-6u45-linux-x64.bin /opt/java/
cd /opt/java/
chmod a+x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
安装完后,设置oracle JDK1.6环境变量到/etc/bash.bashrc(也可以保存到其它环境变量里如~/.bashrc等)里
vim /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
source /etc/bash.bashrc
最后还需要安装open JDK1,7
sudo apt-get -y install openjdk-7-jdk
update-java-alternatives -s java-1.7.0-openjdk-amd64
下面这个命令可以选择使用哪个java版本,这里不需要执行
update-alternatives --config java
4.开始编译android代码
首先进入代码根目录下,然后执行
source build/envsetup.sh #初始化编译环境
lunch #选择编译目标
make -j4 #开始编译,-j后面带的数字表示几个线程一起编译
需要注意的是mt6795的编译需要java 的版本是open java 1.7.x的,而通过lunch选择编译目标后通过java -version查看发现java变成1.6.x了,通过echo $PATH发现其实是在最开始部分加入了/opt/java/jdk1.6.0_45/bin了,因此需要去掉,可以执行如下命令
PATH=$(echo $PATH | cut -d : -f2-)
最后,在编译的过程中还会出现其它问题,比如虚拟内存不够,可以通过增加swap解决,或者磁盘空间不够,最好分配150G以上(虚拟机支持重新分配磁盘大小,不过需要通过fdisk进行格式化然后重新mount)