Ubuntu版本:ubuntu_desktop_12.04_amd64
Andorid版本:自选
官方网站:https://source.android.com/source/initializing.html (务必先看)
1. 安装系统
12.04算是最稳定的版本。安装好Ubuntu后更新所有推荐的更新(不要升级Ubuntu)。
2. 安装jdk
jdk版本与要下载的Android源码版本有关,2.2及一下用jdk 5,2.3用jdk 6。官方已经推荐jdk 7了(而且是openJdk)。个人喜好装oracle的jdk。
sudo mkdir /usr/lib/jvm
sudo cp ~/Downloads/jdk-6u45-linux-x64.bin /usr/lib/jvm
cd /usr/lib/jvm
sudo chmod u+x jdk-6u45-linux-x64.bin
sudo ./jdk-6u45-linux-x64.bin
sudo rm jdk-6u45-linux-x64.bin
sudo gedit /etc/profile
末尾添加环境变量路径:
# set oracle jdk environment
export JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
source /etc/profile
3.安装依赖包:
命令1. 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 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386
如果提示依赖包出错,解决:
sudo apt-get install 依赖包名
再执行一次命令1。
4.下载Android源码:
mkdir ~/bin
PATH=~/bin:$PATH
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo(出问题时:curl http://git-repo.googlecode.com/files/repo-1.12 > ~/bin/repo)
chmod a+x ~/bin/repo
repo init -u https://android.googlesource.com/platform/manifest -b android-4.2.1_r1 (https://android.googlesource.com/platform/manifest/+refs可查看所有分支)
(碰到init失败的情况,原来是git没装,安装了git 和 git_core解决了)
(可能要求升级git:
升级git:
sudo apt-add-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
配置git(不配置的话repo也会要求配置的):
git config --global user.email "your email"
git config --global user.name "your name"
)
repo sync (这步对网速要求高,大概要下载个8G,而且服务器经常unreachable,碰到这种情况就手动中断再次执行命令吧)
设置Ccach(非必做)
(Ccach可以加速重编译)
gedit ~/.bashrc
添加:
# set android complition ccache
export USE_CCACHE=1
export CCACHE_DIR=<path-to-your-cache-directory> (可选,默认位置为~/.ccach)
source ~/.bashrc
在android源码目录下执行:
prebuilts/misc/linux-x86/ccache/ccache -M 50G (这个我没设,不知道默认大小是多大)
5.编译运行:
source build/envsetup.sh
lunch full-eng
make -j4 (j几看你电脑CPU能同时跑几个线程)
emulator
修改环境变量:
gedit ~/.bashrc
source ~/.bashrc
进入编译好的Android文件夹:
cd WO*
source build/envsetup.sh
lunch full-eng
emulator
gdb调试:
adb forward tcp:5039 tcp:5039
adb shell ps
adb shell gdbserver :5039 --attach 787
export PATH=/home/fsz/WORKING_DIRECTORY/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6:$PATH
export PATH=/home/fsz/WORKING_DIRECTORY/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6:$PATH
/home/fsz/WORKING_DIRECTORY/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin
set solib-absolute-prefix /home/fsz/WORKING_DIRECTORY/out/target/product/generic
set solib-search-path /home/fsz/WORKING_DIRECTORY/out/target/product/generic/symbols/system
问题:
make -j4 后:find src' no such file or directory android
解决方法:
make clean
make -j4
查看系统环境命令:env
参考:
https://source.android.com/source/initializing.html
http://862123204-qq-com.iteye.com/blog/1992973
http://blog.csdn.net/gexueyuan/article/details/7772387
http://www.blogjava.net/lihao336/archive/2010/04/19/318758.html