ubuntu 11.10下载和编译Android源码
一、安装ubuntu 11.10
1、swap不记得是1G还是2G了,多方资料查说不建议超过2G,总之我是照办了。更权威点的是:if (M<2) S=M*2 else S=M+2。M->RAM、S->swap。(执行sudo fdisk –l查了分区,那串数字是位数么T^T)
注意$前~表示用户目录开始(即/home/<user name>),而/是系统目录开始。执行pwd可查看当前工作目录。
2、cp /etc/apt/sources.list /etc/apt/sources.list.bak(copy,备份下文件)
deb http://mirrors.163.com/ubuntu/ oneiric main universe restricted multiverse
deb-src http://mirrors.163.com/ubuntu/ oneiric main universe restricted multiverse
deb http://mirrors.163.com/ubuntu/ oneiric-security universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-security universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-updates universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-proposed universe main multiverse restricted
deb http://mirrors.163.com/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-backports universe main multiverse restricted
deb-src http://mirrors.163.com/ubuntu/ oneiric-updates universe main multiverse restricted
sudo -s(或者在下述命令前加sudo,否则是动不了usr/lib下东西的)
mv 文件绝对路径 /usr/lib/jvm/java(移动文件至/usr/lib/jvm/java)
如:sudo mv ~/下载/jdk-6u29-linux-i586.bin /usr/lib/jvm/java
cd /usr/lib/jvm/java(说明是在该目录下罢了)
chmod +x jdk-6u29-linux-i586.bin(增加可执行权限)
./ jdk-6u29-linux-i586.bin(执行文件,会将jdk解压至当前文件夹)
gedit /etc/environment(修改变量)
source ~/.bashrc(设置变量)
update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/jdk1.6.0_29/bin/java 300
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/jdk1.6.0_29/bin/javac 300
update-alternatives --config java(选择默认jdk)
java –version(确认查看版本)
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils lib64z1-dev libc6-dev-amd64 g++-multilib lib64stdc++6
以下载android-4.0.3_r1至/home/<user name>/env/android_src/4.0.3_r1目录下为例。
cd ~/env/android_src/4.0.3_r1/(进入该目录,没有就mkdir)
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo >repo(创建repo文件)
sudo chmod a+x repo(增加可执行权限)
./repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.3_r1(初始化版本库为支线上的android-4.0.3_r1版本)
Your Name [<user name>]:(会跳至这个,要求输入用户名,随意)
Your Email [<user name>@xxx]:(继续要求输入邮箱,随意)
Your identity is: xxx xxx
is this correct [y/N]? y(确认用户名、邮箱)
repo initialized in /home/join/env/android_src/4.0.3_r1(初始化完毕的提示)
1、遇到异常时重执行./repo sync,卡主时先Ctrl+C中断再执行./repo sync,继续下载。
想下载其他指定版本的源码,我是在初始化版本库时故意打错再查看的==。如:./repo init -u https://android.googlesource.com/platform/manifest -b xxx,然后找支线名称(repo没去了解,就这么用了-_-!)。一般具体到哪个发布版本,XXX用发布的版本别名代替就好,都是小写。
问题追加^^
1)DownloadError: android.googlesource.com: <urlopen error [Errno 110] Connection timed out>
4、ubuntu 11.04+获取Android源码(补充篇)
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils xsltproc
sudo gedit /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
gedit ~/.bashrc(添加用户环境变量,注销重登)
cd ~/env/android_src/4.0.3_r1/(进入源码目录)
prebuilt/linux-x86/ccache/ccache -M 50G(设置ccache缓存上限)
sudo apt-get install ccache(下载ccache)
mkdir ~/.bin(创建.bin文件)
cd ~/.bin/(进入.bin文件)
which ccache(确认安装在/usr/bin/ccache)
ln -s /usr/bin/ccache gcc
ln -s /usr/bin/ccache g++
ln -s /usr/bin/ccache arm-linux-gcc
gedit ~/.bashrc(行尾添加如下环境变量配置,注销重登)
which arm-linux-gcc(确认链接至/home/<user name>/.bin/arm-linux-gcc)
ccache –M 50G(设置ccache缓存上限)
然后又在执行的prebuilt/linux-x86/ccache/ccache -M 50G。(好像很ok的样子==)
cd /usr/bin(进入/usr/bin)
ls -l gcc*(查看文件详细信息,gcc*过滤用,结果显示gcc->gcc4.6)
sudo mv gcc gcc.bak(将gcc备份)
sudo ln -s gcc-4.4 gcc(链接gcc4.4至gcc)
ls -l gcc*(再次查看确认,这时gcc->gcc4.4)
ls -l g++*(查看文件详细信息,g++*过滤用,结果显示g++->g++4.6)
sudo mv g++ g++.bak(将g++备份)
sudo ln -s g++-4.4 g++(链接g++4.4至g++)
ls -l g++*(再次查看确认,这时g++->g++4.4)
gcc –v(确认版本)
g++ -v(确认版本,多虑症的孩子T^T)
cd ~/env/android_src/4.0.3_r1/(进入源码目录)
make –j4(开始编译,4表示线程数,为内核总数或其两倍)
cd ~/env/android_src/2.3.3_r1/(进入源码目录)
gedit build/core/main.mk(编辑main.mk)
ifneq (64,$(findstring 64,$(build_arch)))
ifneq (i686,$(findstring i686,$(build_arch)))
LOCAL_CFLAGS += -m64
LOCAL_LDFLAGS += -m64
LOCAL_CFLAGS += -m32
LOCAL_LDFLAGS += -m32
ps:下篇《使用Eclispe进行Android系统应用的开发和调试》
附件:http://down.51cto.com/data/2359991
本文转自winorlose2000 51CTO博客,原文链接:http://blog.51cto.com/vaero/796090,如需转载请自行联系原作者