虽然官网有说明,可是自己自己编译还是会遇到很多问题,这是我自己动手实践的流程,一来写在这儿备忘,二来对别人也有帮助。
1 添加源
后面要安装jdk5,可是ubuntu10.04默认是没有jdk5的源的,需要添加合适的源
$sudo gedit /etc/apt/sources.list
添加以下代码:
deb http://run.hit.edu.cn/ubuntu/ jaunty main restricted universe multiverse
deb-src http://run.hit.edu.cn/ubuntu/ jaunty main restricted universe multiverse
deb http://run.hit.edu.cn/ubuntu/ jaunty-updates main restricted universe multiverse
deb-src http://run.hit.edu.cn/ubuntu/ jaunty-updates main restricted universe multiverse
deb http://run.hit.edu.cn/ubuntu/ jaunty-backports main restricted universe multiverse
deb-src http://run.hit.edu.cn/ubuntu/ jaunty-backports main restricted universe multiverse
deb http://run.hit.edu.cn/ubuntu/ jaunty-security main restricted universe multiverse
deb-src http://run.hit.edu.cn/ubuntu/ jaunty-security main restricted universe multiverse
让改动生效,需要运行
$apt-get update
2 开始安装工具
$sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
老版本的ubuntu好像要安装lib32readline5-dev,我的10.04不需要。
3 将gcc和g++替换成合适的版本
现有的编译器版本太高,语法检查太严格,你可能遇到如下的错误:
development/emulator/qtools/trace_reader.cpp: In function ‘char* ExtractDexPathFromMmap(const char*)’:
development/emulator/qtools/trace_reader.cpp:1012: error: invalid conversion from ‘const char*’ to ‘char*’
development/emulator/qtools/trace_reader.cpp:1015: error: invalid conversion from ‘const char*’ to ‘char*’
make: *** [out/host/linux-x86/obj/EXECUTABLES/bb2sym_intermediates/trace_reader.o] 错误 1
解决办法就是使用gcc-4.3和g++-4.3
高版本的编译器不用卸载,后面我们通过建立链接,指定使用某个版本的编译器
$sudo apt-get install gcc-4.3
$sudo apt-get install g++-4.3
4 给编译器建立软链接
你可能会在编译的时候遇到找不到如下错误:
undefined command gcc
undefined command cc
原因是编译脚本想使用gcc和cc,可是我们的编译器不叫这个名字,而是叫gcc-XXX或者g++-XXX
解决办法是:
$cd usr/bin
$sudo ln -s gcc-4.3 gcc
$sudo ln -s gcc-4.3 cc
5 安装代码下载工具repo
5.1 make sure you have a bin dir in your home dir
$ cd ~
$ mkdir bin
5.2 put ~/bin to PATH env var
$ sudo gedit .bashrc
append "PATH=$PATH:~/bin" in the end
restart terminal
echo $PATH
make sure ~/bin is in PATH
5.3 Download the reposcript and make sure it is executable:
$ curl http://android.git.kernel.org/repo >~/bin/repo
permission denied.
$ chmod 777 bin
$ curl http://android.git.kernel.org/repo >~/bin/repo
$ chmod a+x ~/bin/repo
6 Initializing a Repo client
Create an empty directory to hold your working files:
$ mkdir mydroid
$ cd mydroid
Run "repo init" to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest:
$ repo init -u git://android.git.kernel.org/platform/manifest.git
If you would like to check out a branch other than "master", specify it with -b, like:
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
i need donut
so i input:
repo init -u git://android.git.kernel.org/platform/manifest.git -b donut
When prompted, configure Repo with your real name and email address. If you plan to submit code, use an email address that is associated with a Google account . i used name: mayqlzu, email: [email protected]
7 Getting the files
To pull down files to your working directory from the repositories as specified in the default manifest, run
$ repo sync
download start, it takes a long time. have a good night.
8 添加环境变量
$sudo gedit ~/.bashrc
添加以下代码:
export JAVA_HOME=/usr/lib/jvm/java-5-sun
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/lib
export ANDROID_JAVA_HOME=$JAVA_HOME
export PATH=$PATH:~/mydroid/out/host/linux-x86/bin
export ANDROID_PRODUCT_OUT=~/mydroid/out/target/product/generic
重启终端,让环境变量生效
9 编译
$cd ~/mydroid
$make
应该不会有问题。