Android2.1源码编译,VirtualBox虚拟机,jdk1.5
在同事和网友的帮助下,实现了一把在Virtualbox 虚拟中中编译Android源码,过程主要如下:
前提:事先下载好了 android2.1源码和jdk1.5,通过共享到虚拟机;
1,通过virtualbox打到主机与虚拟机共享 手动挂载 a,在虚拟机分配数据空间,指向主机,另外取名(最好不用默认的名称,建议修改,LinuxShared) b,将需要共享的文件放入主机的文件夹内(即上面指向的文件夹,该文件夹内有android2.1源码,jdk5,等) c,sudo mount -t vboxsf LinuxShared /home/zero/shared (zero是linux用户名对应的文件夹目录,shared是zero文件夹下的子目录) 该命令只在当前操作中有效,下次重启模拟器还需要执行该命令才能数据共享; 自动挂载 a,可以在/etc/fstab中添加一项 linuxShared /home/zero/shared vboxsf rw,gid=100,uid=1000,auto 0 0 这样就能够自动挂载了。 (我试过没用,不知道写错了哪里) 卸载的话使用下面的命令: sudo umount -f /home/zero/shared 2,Linux下安装jdk a,编译Android源码需要JDK1.5版(主要是需要其中的javadoc),1.6版是不兼容的。JDK1.5已经停止支持, 其最终的版本是JDK 5.0 Update 22。 从Sun官网上下载:http://java.sun.com/javase/downloads/5u22/jdk 选择平台Linux,勾选同意许可协议: 下载时选择jdk-1.5.0_22-linux-i586.bin 这里我在主机中下载好了,直接从 shared文件夹中拷贝出来, 目录 /home/zero/java/jdk-1.5.0_22-linux-i586.bin b,执行安装,需要有权限 赋予权限 才能够安装 默认都是没有执行权限的,可以通过 $ls -l 命令查询到相关信息,所以首先第一步是要将安装文件赋予可执行权限, 可以通过命令 $ sudo chmod u+x /home/zero/java/jdk-6u20-linux-i586.bin (jdk存放目录)来实现。 $ cd /zero/java/ 进入安装文件所在目录,然后执行命令 $ ./jdk-1_5_0_22-linux-i586.bin 来安装。 c,一直回车,直至输入yes,确定安装,安装之后 在 /home/zero/java目录下有新生成一个目录,意味着安装成功。 d,再配置环境变量 sudo vim /etc/environment或者 (试过没用) sudo vi /etc/environment或者 sudo gedit /etc/environment都是文字编辑环境变量工具 PATH="...... :/home/zero/java/jdk1.5.0_22/bin"(:之前是之前已有内容,添加新的用:隔开) CLASSPATH=".:/home/zero/java/jdk1.5.0_22/lib" JAVA_HOME="/home/zero/java/jdk1.5.0_22" 因为ubuntu可能还会有默认的jdk,如openjdk;所以,为了使默认使用的是我们安装的jdk,还需执行如下命令: update-alternatives --install /usr/bin/java java /home/zero/java/jdk1.5.0_22/bin/java 300 update-alternatives --install /usr/bin/javac javac /home/zero/java/jdk1.5.0_22/bin/javac 300 这2行命令告诉系统jvm的存在,然后可以通过 sudo update-alternatives --config java sudo update-alternatives --config javac 来切换java跟javac的版本 e,java -version 查看版本号,如果能成功查看则ok 3. sdk的编译 a,安装sdk2.1之前需要下载一些工具包来编译adk, 而在进行下面的代码之前,必须有root权限 Ubuntu安装好后,默认root用户是没有密码的,但是默认关闭了root用户的登录,所以无法登陆 安装的时候设置的用户是唯一可以执行sudo命令的用户 如果非要用root用户登录,需要用安装的时候创建的用户登录进去以后,执行命令 sudo passwd root 设置密码以后,就可以使用 su root 来切换到root用户了 # apt-get install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build- essential zip curl libncurses5-dev zlib1g-dev (数字 1) # apt-get install valgrind # apt-get install lib32readline5-dev (该软件包我当时没找到,但libreadline5-dev可以找到) b,然后进入到sdk(eclair源码)主目录 执行 . ./build/envsetup.sh 两个点之间有一个空格 tapas 之后会出现4个问句,分别选 1, 1, utc100, eng mm 建议下面的操作在之前就做(我就先检查 gcc --version ,如果是4.4的就改) 在mm的过程可能会出现变异错误的问题,导致改原因的可能是由于android编译要求是gcc4.3 ,如果是gcc 4.4 的话就可能出编译错误 恰好ubuntu10中自带的就是gcc4.4,因此我们需要调整gcc4.3的版本,方法如下:(gcc --version) sudo apt-get install gcc-4.3 g++-4.3 sudo apt-get install g++-multlib g++-4.3-multilib (64bit系统需要) 然后修改链接 cd /usr/bin/ ls -l 可以看到gcc只是个链接而已,指向4.4 修改下 指向4.3 sudo ln -snf gcc-4.3 gcc sudo ln -snf g++-4.3 g++ sudo ln -snf cpp-4.3 cpp (不知道是不是必须的) sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 40 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 30 (可不要) 把gcc4.3 4.4都加进去,然后我们可以通过 sudo update-alternatives --config gcc 来切换gcc的版本了 然后编译的时候需要重新执行 . ./build/envsetup.sh tapas (这里跟着它走就好了,有默认选项的,1 1 utc100 eng) mm