Ubuntu11下android 源码编译 step by step -1 安装ubuntu和jdk
1. 安装ubuntu。
安装ubuntu,我在网上下载的是ubuntu11. 可以到官网下载。http://www.ubuntu.com/download
ubuntu 的安装有很多方法
第一种:虚拟机最好不要用,因为速度慢。
第二种:wubi建议使用,本人采用此方法。此安装可以windows下像安装应用程序一样安装,卸载也很方便。其中的一个缺点就是最大只能分配30G的硬盘。不过对于安装android sdk,下载源码和编译应该够用了。---最新验证,wubi安装Ubuntu11.10+jdk1.6环境下,编译android4.0.3源码过程中,30G空间会提示空间不足。剩余800M空间的时候,还在编译。这还不包括我把下载的SDK剪切到了其他盘。2011-12-27,建议光盘进行硬盘安装。
第三种:另外就是直接光盘安装ubuntu了,可安装双系统,或者直接使用整个硬盘安装ubuntu,需要硬盘分区,
ubuntu下的分区概念和windows下完全不同,建议有linux基础的人使用。记得备份文件。切忌。
另外:官方文档说明,froyo2.2只能在jdk1.5下编译,否则会出错,而且ubuntu建议安装64位。
但我装的ubuntu11 32位 +gingerbread2.3.3+jdk1.6,基本编译完成,没有出现问题。
2. 更改ubuntu 更新源。
首先要对ubuntu的更新源进行更新,主要的是JDK的更新源。
开启终端,输入命令”sudo gedit /etc/apt/sources.list”,弹出文本文件,在最后加上以下内容:
deb http://archive.canonical.com/ubuntu lucid partner
deb-src http://archive.canonical.com/ubuntu lucid partner
这个很重要,因为通过命令行安装jdk的话,会用到该源。
下面的这个更新源看你心情了,高兴就加上,不高兴就算了。
#Ubuntu官方源
deb http://cn.archive.Ubuntu.com/ubuntu/ natty multiverse
deb-src http://cn.archive.Ubuntu.com/ubuntu/ natty multiverse
deb http://cn.archive.Ubuntu.com/ubuntu/ natty-updates multiverse
deb-src http://cn.archive.Ubuntu.com/ubuntu/ natty-updates multiverse
deb http://security.Ubuntu.com/ubuntu natty-security main restricted
deb-src http://security.Ubuntu.com/ubuntu natty-security main restricted
deb http://security.Ubuntu.com/ubuntu natty-security universe
deb-src http://security.Ubuntu.com/ubuntu natty-security universe
deb http://security.Ubuntu.com/ubuntu natty-security multiverse
deb-src http://security.Ubuntu.com/ubuntu natty-security multiverse
deb http://archive.canonical.com/Ubuntu natty partner
deb-src http://archive.canonical.com/Ubuntu natty partner
#Ubuntu 11.04台湾源(推荐)
deb http://tw.archive.Ubuntu.com/ubuntu/ natty main universe restricted multiverse
deb-src http://tw.archive.Ubuntu.com/ubuntu/ natty main universe restricted multiverse
deb http://tw.archive.Ubuntu.com/ubuntu/ natty-security universe main multiverse restricted
deb-src http://tw.archive.Ubuntu.com/ubuntu/ natty-security universe main multiverse restricted
deb http://tw.archive.Ubuntu.com/ubuntu/ natty-updates universe main multiverse restricted
deb-src http://tw.archive.Ubuntu.com/ubuntu/ natty-updates universe main multiverse restricted
#Ubuntu11.04网易源(速度很快、推荐)
deb http://mirrors.163.com/Ubuntu/ natty main universe restricted multiverse
deb-src http://mirrors.163.com/Ubuntu/ natty main universe restricted multiverse
deb http://mirrors.163.com/Ubuntu/ natty-security universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-security universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-updates universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-updates universe main multiverse restricted
#Ubuntu 11.04 骨头源 (bones7456架设的一个Ubuntu源 ,提供ubuntu,deepin)
deb http://Ubuntu.srt.cn/ubuntu/ natty main universe restricted multiverse
deb-src http://Ubuntu.srt.cn/ubuntu/ natty main universe restricted multiverse
deb http://Ubuntu.srt.cn/ubuntu/ natty-security universe main multiverse restricted
deb-src http://Ubuntu.srt.cn/ubuntu/ natty-security universe main multiverse restricted
deb http://Ubuntu.srt.cn/ubuntu/ natty-updates universe main multiverse restricted
deb http://Ubuntu.srt.cn/ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://Ubuntu.srt.cn/ubuntu/ natty-proposed universe main multiverse restricted
deb http://Ubuntu.srt.cn/ubuntu/ natty-backports universe main multiverse restricted
deb-src http://Ubuntu.srt.cn/ubuntu/ natty-backports universe main multiverse restricted
deb-src http://Ubuntu.srt.cn/ubuntu/ natty-updates universe main multiverse restricted
#upaworld 源,提供 ArchLinux,Everest,FreeBSD,Fedora,LFS,Magiclinux,Mandriva,OpenOffice,openSUSE,Puppy,Red Hat,Slitaz,Turbolinux,Ubuntu,中标普华
deb http://mirror.lupaworld.com/Ubuntu/ natty main universe restricted multiverse
deb-src http://mirror.lupaworld.com/Ubuntu/ natty main universe restricted multiverse
deb http://mirror.lupaworld.com/Ubuntu/ natty-security universe main multiverse restricted
deb-src http://mirror.lupaworld.com/Ubuntu/ natty-security universe main multiverse restricted
deb http://mirror.lupaworld.com/Ubuntu/ natty-updates universe main multiverse restricted
deb http://mirror.lupaworld.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://mirror.lupaworld.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb http://mirror.lupaworld.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirror.lupaworld.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirror.lupaworld.com/Ubuntu/ natty-updates universe main multiverse restricted
#网易开源镜像站,提供FreeBSD,OpenBSD,archlinux,centos,cygwin,debian,Fedora,gentoo,kernel,openSUSE,slackware,Ubuntu
deb http://mirrors.163.com/Ubuntu/ natty main universe restricted multiverse
deb-src http://mirrors.163.com/Ubuntu/ natty main universe restricted multiverse
deb http://mirrors.163.com/Ubuntu/ natty-security universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-security universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-updates universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-proposed universe main multiverse restricted
deb http://mirrors.163.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.163.com/Ubuntu/ natty-updates universe main multiverse restricted
#搜狐开源镜像站,提供 CPAN,FreeBSD,NetBSD,OpenBSD,apache,archlinux,centos,cygwin,dag,debian,Fedora,gentoo,kernel,lfs,mysql,nginx,openSUSE,#PHP,rpmfusion,slackware,Ubuntu
deb http://mirrors.shlug.org/Ubuntu/ natty main universe restricted multiverse
deb-src http://mirrors.shlug.org/Ubuntu/ natty main universe restricted multiverse
deb http://mirrors.shlug.org/Ubuntu/ natty-security universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-security universe main multiverse restricted
deb http://mirrors.shlug.org/Ubuntu/ natty-updates universe main multiverse restricted
deb http://mirrors.shlug.org/Ubuntu/ natty-proposed universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-proposed universe main multiverse restricted
deb http://mirrors.shlug.org/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-backports universe main multiverse restricted
deb-src http://mirrors.shlug.org/Ubuntu/ natty-updates universe main multiverse restricted
然后关闭文本编辑器。然后执行下面命令进行更新。
sudo apt-get update
3. 安装jdk
终端键入
sudo apt-get install sun-java6-jdk
安装提示进行安装 , 碰到Y/N ,当然键入 Y 了。
安装完成后,配置环境变量
与Windows不同,Ubuntu是没有注册表的,故安装完成后,我们需要把我们安装JDK的目录告诉系统,故在刚才的终端里执行如下命令
(如果是新开的终端,没有执行过“sudo -i”,则需要在命令前+“sudo”获得权限)
gedit /etc/environment
在会弹出一个文本编辑器,里面显示
PATH=”……” |
其中省略号部分是其默认的路径,这里我们不要动它,我们需要对这个进行一些修改,将我们的JDK安装路径写进去,告诉系统我们的JDK装在哪里,去哪里调用,故做如下修改:
i. 在原有的 PATH=”……” 的省略号里面添加:
代码:
PATH=”……:/usr/lib/jvm/java-6-sun-1.6.0.26/bin” |
ii. 添加两行,输入如下内容:
代码:
CLASSPATH=.:/usr/lib/jvm/java-6-sun-1.6.0.26/lib JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.26 |
最后生成如下形式:
代码:
PATH=”……:/usr/lib/jvm/java-6-sun-1.6.0.26/bin” CLASSPATH=.:/usr/lib/jvm/java-6-sun-1.6.0.26/lib JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.26 |
其中,省略号部分是文件原有内容,我们在后面新加了一部分内容和两个新行-红色部分。修改完成后保存退出。
使用下面命令可查看jdk版本
java -version