如何在32位ubuntu11.10 下编译android 4.0.1源码和goldfish内核

一准备工作

1安装javasdk6

(1)从jdk官方网站http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u29-download-513648.html下载jdk-6u29-linux-i586.bin文件。

(2)执行jdk安装文件

view plaincopy to clipboardprint?

  1. $chmod a+x jdk-6u29-linux-i586.bin
  2. $jdk-6u29-linux-i586.bin

$chmod a+x jdk-6u29-linux-i586.bin $jdk-6u29-linux-i586.bin

(3)配置jdk环境变量

view plaincopy to clipboardprint?

  1. $sudo vim /etc/profile

$sudo vim /etc/profile

view plaincopy to clipboardprint?

  1. #JAVAEVIRENMENT
  2. exportJAVA_HOME=/usr/lib/java/jdk1.6.0_29
  3. exportJRE_HOME=$JAVA_HOME/jre
  4. exportCLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
  5. exportPATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

#JAVAEVIRENMENT exportJAVA_HOME=/usr/lib/java/jdk1.6.0_29 exportJRE_HOME=$JAVA_HOME/jre exportCLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH exportPATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

保存后退出编辑,并重启系统。

2安装依赖包

view plaincopy to clipboardprint?

  1. $sudo apt-get install git-core gnupg flex bison gperf build-essential\
  2. zipcurlzlib1g-devlibc6-devlib32ncurses5-devia32-libs\
  3. x11proto-core-devlibx11-devlib32readline5-devlib32z-dev\
  4. libgl1-mesa-devg++-multilibmingw32tofrodospython-markdown\
  5. libxml2-utils

$sudo apt-get install git-core gnupg flex bison gperf build-essential\ zipcurlzlib1g-devlibc6-devlib32ncurses5-devia32-libs\ x11proto-core-devlibx11-devlib32readline5-devlib32z-dev\ libgl1-mesa-devg++-multilibmingw32tofrodospython-markdown\ libxml2-utils

3用repo工具下载源码

(1)初始化repo

view plaincopy to clipboardprint?

  1. $cd ~
  2. $mkdir bin
  3. $curlhttps://dl-ssl.google.com/dl/googlesource/git-repo/repo>~/bin/repo
  4. $chmod a+x ~/bin/repo
  5. $exportPATH=$PATH:~/bin(导出环境变量)

$cd ~ $mkdir bin $curlhttps://dl-ssl.google.com/dl/googlesource/git-repo/repo>~/bin/repo $chmod a+x ~/bin/repo $exportPATH=$PATH:~/bin(导出环境变量)

(2)下载android最新源码

view plaincopy to clipboardprint?

  1. $mkdir android
  2. $cd android
  3. $ repo init -u https://android.googlesource.com/platform/manifest -bandroid-4.0.1_r1
  4. ...(输入用户名和邮箱名)
  5. $repo sync -j5
  6. ...(此处用5个线程开始下载源码,下载过程及其漫长,需要耐心等待)

$mkdir android $cd android $ repo init -u https://android.googlesource.com/platform/manifest -bandroid-4.0.1_r1 ...(输入用户名和邮箱名) $repo sync -j5 ...(此处用5个线程开始下载源码,下载过程及其漫长,需要耐心等待)

二 编译源码

1开始编译

view plaincopy to clipboardprint?

  1. $source build/envsetup.sh
  2. includingdevice/samsung/maguro/vendorsetup.sh
  3. includingdevice/samsung/tuna/vendorsetup.sh
  4. includingdevice/ti/panda/vendorsetup.sh
  5. includingsdk/bash_completion/adb.bash
  6. $make-j4(此处用4个线程编译)

$source build/envsetup.sh includingdevice/samsung/maguro/vendorsetup.sh includingdevice/samsung/tuna/vendorsetup.sh includingdevice/ti/panda/vendorsetup.sh includingsdk/bash_completion/adb.bash $make-j4(此处用4个线程编译)

编译完成后,会看到类似的输出:

view plaincopy to clipboardprint?

  1. Targetramdisk:out/target/product/generic/ramdisk.img
  2. Targetuserdatafsimage:out/target/product/generic/userdata.img
  3. Installedfilelist:out/target/product/generic/installed-files.txt

Targetramdisk:out/target/product/generic/ramdisk.img Targetuserdatafsimage:out/target/product/generic/userdata.img Installedfilelist:out/target/product/generic/installed-files.txt

2编译遇到的问题

编译错误:

view plaincopy to clipboardprint?

  1. <命令行>:0:0:错误:“_FORTIFY_SOURCE”重定义[-Werror]
  2. <built-in>:0:0:附注: 这是先前定义的位置
  3. cc1plus:所有的警告都被当作是错误
  4. make:*** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o]错误 1

<命令行>:0:0:错误:“_FORTIFY_SOURCE”重定义[-Werror] <built-in>:0:0:附注: 这是先前定义的位置 cc1plus:所有的警告都被当作是错误 make:*** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o]错误 1

原因:

因机器上的gcc版本过高,需替换成4.4.6重新进行编译。

解决方法:

1)安装4.4版本的gcc和g++

view plaincopy to clipboardprint?

  1. $ sudo apt-get install gcc-4.4
  2. $ sudo apt-get install g++-4.4

$ sudo apt-get install gcc-4.4 $ sudo apt-get install g++-4.4

2)设置gcc版本,使gcc链接到gcc-4.4

view plaincopy to clipboardprint?

  1. $ ls -l /usr/bin/gcc*
  2. lrwxrwxrwx 1 root root 7 2011-11-01 23:56 /usr/bin/gcc -> gcc-4.6
  3. -rwxr-xr-x 1 root root 224544 2011-10-06 05:47 /usr/bin/gcc-4.4
  4. -rwxr-xr-x 1 root root 302104 2011-09-17 05:43 /usr/bin/gcc-4.6
  5. $ cd /usr/bin
  6. $ sudo mv gcc gcc.bak
  7. $ sudo ln -s gcc-4.4 gcc

$ ls -l /usr/bin/gcc* lrwxrwxrwx 1 root root 7 2011-11-01 23:56 /usr/bin/gcc -> gcc-4.6 -rwxr-xr-x 1 root root 224544 2011-10-06 05:47 /usr/bin/gcc-4.4 -rwxr-xr-x 1 root root 302104 2011-09-17 05:43 /usr/bin/gcc-4.6 $ cd /usr/bin $ sudo mv gcc gcc.bak $ sudo ln -s gcc-4.4 gcc

3)设置g++版本,使g++链接到g++-4.4

view plaincopy to clipboardprint?

  1. $ sudo mv g++ g++.bak
  2. $ sudo ln -s g++-4.4 g++

$ sudo mv g++ g++.bak $ sudo ln -s g++-4.4 g++

4)设置完毕后,重新进行编译即可

3从模拟器启动编译后的镜像文件

1)设置环境变量:

view plaincopy to clipboardprint?

  1. export PATH=~/android/out/host/linux-x86/bin:$PATH
  2. export ANDROID_PRODUCT_OUT=~/android/out/target/product/generic

export PATH=~/android/out/host/linux-x86/bin:$PATH export ANDROID_PRODUCT_OUT=~/android/out/target/product/generic

其中linux-x86/bin存放模拟器emulator工具,product/generic存在编译后的镜像文件。

2)启动模拟器

view plaincopy to clipboardprint?

  1. $emulator
  2. emulator:WARNING: system partition size adjusted to match image file (162 MB >66 MB)

$emulator emulator:WARNING: system partition size adjusted to match image file (162 MB >66 MB)

启动后的截图:

如何在32位ubuntu11.10 下编译android 4.0.1源码和goldfish内核

三 编译androidgoldfish内核

1)进入android4.0.1源码目录,下载goldfish内核源码

view plaincopy to clipboardprint?

  1. $ mkdir kernel
  2. $ cd kernel
  3. $ git clone http://android.googlesource.com/kernel/goldfish.git
  4. $ cd goldfish
  5. $ git branch -a
  6. * (no branch)
  7. master
  8. remotes/origin/HEAD -> origin/master
  9. remotes/origin/android-goldfish-2.6.29
  10. remotes/origin/master
  11. $ git checkout remotes/origin/android-goldfish-2.6.29

$ mkdir kernel $ cd kernel $ git clone http://android.googlesource.com/kernel/goldfish.git $ cd goldfish $ git branch -a * (no branch) master remotes/origin/HEAD -> origin/master remotes/origin/android-goldfish-2.6.29 remotes/origin/master $ git checkout remotes/origin/android-goldfish-2.6.29

2)修改Makefile

view plaincopy to clipboardprint?

  1. goldfish$ gedit Makefile

goldfish$ gedit Makefile

修改

view plaincopy to clipboardprint?

  1. ARCH ?=$(SUBARCH)
  2. CROSS_COMPILE ?=

ARCH ?=$(SUBARCH) CROSS_COMPILE ?=

view plaincopy to clipboardprint?

  1. ARCH ?=arm
  2. CROSS_COMPILE ?=arm-eabi-

ARCH ?=arm CROSS_COMPILE ?=arm-eabi-

3)导出交叉编译器目录为环境变量

$ export PATH=$PATH:~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin

4)编译内核

view plaincopy to clipboardprint?

  1. goldfish$ make goldfish_armv7_defconfig
  2. goldfish$ make

goldfish$ make goldfish_armv7_defconfig goldfish$ make

编译完成后,可看到类似如下的输出:

view plaincopy to clipboardprint?

  1. OBJCOPY arch/arm/boot/zImage
  2. Kernel: arch/arm/boot/zImage is ready

OBJCOPY arch/arm/boot/zImage Kernel: arch/arm/boot/zImage is ready

5)从模拟器中启动内核镜像

view plaincopy to clipboardprint?

  1. $emulator -kernel ~/android/kernel/goldfish/arch/arm/boot/zImage &

$emulator -kernel ~/android/kernel/goldfish/arch/arm/boot/zImage &

启动模拟器后,可从Settings->System->AboutPhone中查看内核版本信息。

如何在32位ubuntu11.10 下编译android 4.0.1源码和goldfish内核

如何在32位ubuntu11.10 下编译android 4.0.1源码和goldfish内核

如何在32位ubuntu11.10 下编译android 4.0.1源码和goldfish内核

我的网站:www.wak99.com

你可能感兴趣的:(android 4.0)