代码改变世界

Android source开发环境搭建

2010-11-23 15:07  RayLee  阅读(1294)  评论(0编辑  收藏  举报

众所周知,Android是开源的。这样就可以下载Android的全部代码,进行编译生成二进制镜象文件。

开发平台

Ubuntu.

工具安装

$ sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf

    libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl

    libncurses5-dev zlib1g-dev

源码下载

$ cd ~

$ mkdir bin

$ curl http://android.git.kernel.org/repo > ~/bin/repo

$ chmod a+x ~/bin/repo

repo是一个工具,用来配合Git下载源码的。

$ export PATH=$HOME/bin:$PATH

$ mkdir mydroid

$ cd mydroid

$ repo init –u git://android.git.kernel.org/platform/manifest.git –b [BRANCH_NAME]

$ repo sync

编译生成

$ cd mydroid

$ make

官方指导可访问:http://source.android.com/source/download.html

另一篇可参考的文章:http://mmmyddd.freeshell.net/wiki/android/build.html

运行模拟器

要运行模拟器,至少需要4个images:

- system.img   : the *initial* system image.
- ramdisk.img  : the ramdisk image used to boot the system.
- userdata.img : the *initial* user data image (see below).
- kernel-qemu  : the emulator-specific Linux kernel image.

编译完成后,生成的system.img,ramdisk.img,userdata.img在目录<src_directory>/out/target/product/generic/下。

kernel-qemu在目录<src_directory>/prebuilt/android-arm/kernel/下。

模拟器启动时,自动在路径<src_directory>/prebuilt/android-arm/kernel/下查找kernel-qemu,但还要用户显示指明另外3个images的路径。模拟器通过查看环境变量ANDROID_PRODUCT_OUT来确定另外3个images的路径。因此,启动前先设置export ANDROID_PRODUCT_OUT=<src_directory>/out/target/product/generic。

设置好环境变量后,切换到<src_directory>/out/host/linux-x86/bin/目录,运行./emulator 就可以加载生成的images运行Android系统了。

如果在运行emulator时出现诸如“emulator: ERROR: There is no user data image in your build directory. Please make a full build”的错误,请先检查文件的权限。

emulator相关的文档:

ray@ray-ubuntu:~/android_2_2/out/host/linux-x86/bin$ ./emulator -help-build-images

  The emulator detects that you are working from the Android build system
  by looking at the ANDROID_PRODUCT_OUT variable in your environment.

  If it is defined, it should point to the product-specific directory that
  contains the generated system images.
  In this case, the emulator will look by default for the following image
  files there:

    - system.img   : the *initial* system image.
    - ramdisk.img  : the ramdisk image used to boot the system.
    - userdata.img : the *initial* user data image (see below).
    - kernel-qemu  : the emulator-specific Linux kernel image.

  If the kernel image is not found in the out directory, then it is searched
  in <build-root>/prebuilt/android-arm/kernel/.

  Skins will be looked in <build-root>/sdk/emulator/skins/

  You can use the -sysdir, -system, -kernel, -ramdisk, -datadir, -data options
  to specify different search directories or specific image files. You can
  also use the -cache and -sdcard options to indicate specific cache partition
  and SD Card image files.

  For more details, see the corresponding -help-<option> section.

  Note that the following behaviour is specific to 'build mode':

  - the *initial* system image is copied to a temporary file which is
    automatically removed when the emulator exits. There is thus no way to
    make persistent changes to this image through the emulator, even if
    you use the '-image <file>' option.

  - unless you use the '-cache <file>' option, the cache partition image
    is backed by a temporary file that is initially empty and destroyed on
    program exit.

  SPECIAL NOTE: If you are using the emulator with the Android SDK, the
  information above doesn't apply. See -help-sdk-images for more details.