原文网址:http://www.mcuos.com/thread-4553-1-1.html
建立编译环境1.在VirtualBox上安装Ubuntu2.安装JDK $ sudo apt-get install sun-java5-jdk 或 $ sudo apt-get install sun-java6-jdk (donut 1.6)3.安装flex,bison,gperf,libsdl-dev,libesd0-dev,libwxgtk2.6-dev(可选),build-essential,zip,curl。 $ sudo apt-get install flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev4.安装Valgrind(可选),此工具可以帮你查找内存泄漏、堆栈破坏以及数组访问越界等错误。 $ sudo apt-get install valgrind5.下载Android源代码从Android官方下载donut分支的Android源代码sudo apt-get install git-core curlcurl http://android.git.kernel.org/repo >~/bin/repochmod a+x ~/bin/repocd ~/bin/ $ ./repo init -u git://android.git.kernel.org/platform/manifest.git -b android-1.6_r2 $ ./repo sync6.在 ~/.bashrc 加环境变量。 $ vim ~/.bashrc在.bashrc文件的最后面加入如下2行,即将JDK的安装路径加入到环境变量中 export JAVA_HOME=/usr/lib/jvm/java-6-sun export ANDROID_JAVA_HOME=$JAVA_HOME完成后,$source ~/.bashrc即可生效。运行 $ java -version 将出现下面提示: [root@Neil java]# java -version java version "1.6.0_11" Java(TM) SE Runtime Environment (build 1.6.0_11-b03) Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing) [root@Neil java]# 说明Java已经成功被安装了通过$ update-alternatives --config javadoc$ sudo update-alternatives --config java$ sudo update-alternatives --config javac然后选一个编号,就切换过去了。编译Android $ cd android //(进入android目录) $ make //(编译android)注意:编译时要确保系统的内存在1.2GM以上,且有足够的硬盘可用空间,否则会编译失败终止。 Android编译环境提供了”showcommands”选项来显示编译命令行,如: $ make showcommands1.5_r2版编译出错的解决方法:The Android code contains a bug that hasn’t been solved up to the date of this article.So before you start compiling the code, you’ll need a few modifications, or the build will fail (after consuming some of your time and patience). The error is:external/qemu/sockets.c: In function 'sock_address_init_resolve':external/qemu/sockets.c:637: error: 'EAI_NODATA' undeclared (first usein this function)external/qemu/sockets.c:637: error: (Each undeclared identifier isreported only onceexternal/qemu/sockets.c:637: error: for each function it appears in.)make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_intermediates/sockets.o] Error 1To fix this, before compiling the android code, open ~/mydroid/external/qemu/sockets.c and add#define __USE_GNUjust before the #include <netdb.h>新编译的system.img不能正常使用sdcard 的解决办法: $ mount -t vfat /dev/block//vold/179:0 /sdcard 也可以更改system/core/vold程序运行emulator我们这里使用已经编译好的模拟器kernel镜像,即kernel-qemu,位于android/prebuilt/android-arm/kernel目录下,然后运行模拟器。1.在 ~/.bashrc 加环境变量。(本项可选) $ vim ~/.bashrc在.bashrc文件的最后面加入如下2行,即将Android工具的路径 export PATH=/archer/external/android/out/host/linux-x86/binPATH export ANDROID_PRODUCT_OUT=/archer/external/android/out/target/product/generic export ANDROID_SWT=/android/out/host/linux-x86/framework 2.创建Android虚拟设备 $ cd android/out/host/linux-x86/bin (进入模拟器程序所在目录) $ ./android create avd -t 2 -n g1其中 -t 指定TargetID (Android 1.5 SDK的ID为2,Android 1.0 SDK的ID为1),-n指定创建的Android虚拟设备名字。3.运行emulator $ cd android/out/host/linux-x86/bin (进入模拟器程序所在目录) $ ./emulator -avd g1 或者 $ ./emulator -avd g1 -scale 0.8其中 -avd指定Android设备名,-scale指定缩放比例。按 Ctrl + F12 可以使模拟器屏幕旋转90度,即横屏、竖屏切换。4.删除创建的Android虚拟设备 $ ./android delete avd -n g1编译linux kernel直接编译Android源码时,并没有编译 linux kernel。如果只运行模拟器,不用编译 linux kernel。从emulator获取内核编译参数的配置文件: 启动模拟器 $ adb pull /proc/config.gz . 解压缩config.gz $ gzip -d config.gz 将config文件替换kernel文件夹下的.config文件。根据需要,修订config与Makefile配置文件编译模块Android中的一个应用程序可以单独编译,编译后需要重新生成system.img。在Android目录下运行 $ . build/envsetup.sh 或者 $ source build/envsetup.sh ,然后就会多出几个可用的命令:- croot: Changes directory to the top of the tree.- m: Makes from the top of the tree.- mm: Builds all of the modules in the current directory.- mmm: Builds all of the modules in the supplied directories.- cgrep: Greps on all local C/C++ files.- jgrep: Greps on all local Java files.- resgrep: Greps on all local res/*.xml files.- godir: Go to the directory containing a file.- printconfig: 当前build的配置情况.可以使用 --help查看用法。如:在修改了某一个模块以后,可以使用 $ mmm <目录> 来重新编译所有在<目录>中的所有模块,使用 $ mm 编译当前目录中的所有模块。编完之后,即修改了Android系统以后,可以使用 $ make snod 重新生成system.img。转载于:https://www.cnblogs.com/wi100sh/p/4338219.html