编译Android平台以及SDK

编译Android平台以及SDK

完全编译

编译映像
cd ~/android/src
make

映像编译成功后会在目录 ~/android/src/out/target/product/generic 下产生一些image文件

ramdisk.img system.img userdata.img android-info.txt

验证,运行这些模块:

export ANDROID_PRODUCT_OUT=/home/justin/android/src/out/target/product/generic
cd out/host/linux-x86/bin
./emulator
SDK编译

在做完一次完全编译后,就可以build SDK了。

make sdk

注意:如果需要build SDK,需要安装sun-java5-jdk, 而不是sun-java6-jdk,否则会出现如下错误:

build/core/product_config.mk:207: WARNING: adding test OTA key
============================================
TARGET_PRODUCT=generic
TARGET_BUILD_VARIANT=eng
TARGET_SIMULATOR=
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=
============================================
Combining NOTICE files: out/target/product/generic/obj/NOTICE.txt
Finding NOTICE files: out/host/linux-x86/obj/NOTICE_FILES/hash-timestamp
Combining NOTICE files: out/host/linux-x86/obj/NOTICE.txt
Package: out/target/product/generic/generic-img-eng.justin.zip
SDK buildinfo: out/target/product/generic/sdk/sdk-build.prop
Docs droiddoc: out/target/common/docs/dx
javadoc: 错误 - 在 doclet 类 DroidDoc 中,方法 start 已抛出异常 java.lang.reflect.InvocationTargetException
com.sun.tools.javac.code.Symbol$CompletionFailure: 未找到 sun.util.resources.OpenListResourceBundle 的类文件

此时,可以考虑重新安装sun jdk5, 或者直接从http://java.sun.com/javase/downloads 下载到~/android/downloads/jdk-1_5_0_17-linux-i586.bin

sudo apt-get install sun-java5-jdk

并设置相应的.bashrc命令。

sdk编译成功后会在~/android/src/out/host/linux-x86/sdk/ 生成sdk的文件目录和压缩包:

android-sdk_eng.justin_linux-x86
android-sdk_eng.justin_linux-x86.zip

并在~/android/src/out/target/product/generic(generic是默认的产品名)下打包所有的映像文件:

generic-img-eng.justin.zip

生成的SDK目录结构为:

  /home/justin/android/src/out/host/linux-x86/sdk/android-sdk_eng.justin_linux-x86:
  总计 32
  drwxrwx---  6 justin justin 4096 02-13 17:06 .
  drwxr-x---  3 justin justin 4096 02-13 17:09 ..
  drwxrwx---  2 justin justin 4096 02-13 17:06 add-ons
  drwxrwx--- 14 justin justin 4096 02-13 17:06 docs
  -rw-rw----  1 justin justin  172 02-13 17:08 documentation.html
  drwxrwx---  3 justin justin 4096 02-13 17:06 platforms
  -rw-rw----  1 justin justin  225 02-13 17:08 RELEASE_NOTES.txt
  drwxrwx---  3 justin justin 4096 02-13 17:08 tools

安装生成的SDK只需要在.bashrc中增加:

export PATH=$PATH:/home/justin/android/src/out/host/linux-x86/sdk/android-sdk_eng.justin_linux-x86/tools

为了使用方便,将生成的SDK目录链结至~/android/sdk:

ln -sf /home/justin/android/src/out/host/linux-x86/sdk/android-sdk_eng.justin_linux-x86/tools \
       ~/android/sdk

模块编译

在src目录执行:

cd ~/android/src
. build/envsetup.sh

envsetup.sh 提供了一些的bash函数定义,当运行了envsetup.sh后就可以使用help 命令来查看:

help

得到这些命令的帮助信息:

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- 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.

Look at the source to view more functions. The complete list is:
add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant croot findmakefile gd
bclient get_abs_build_var getbugreports get_build_var getprebuilt gettop help isviewserverstarted jgrep lunch m mm mmm pid
 printconfig print_lunch_menu resgrep runhat runtest setpaths set_sequence_number set_stuff_for_environment settitle smoke
test startviewserver stopviewserver tapas tracedmdump

其中对模块的编译有帮助的是tapas、m、mm、mmm这几个命令。

1.tapas - 以交互方式设置build环境,以下是运行效果:

tapas

第一步,选择目标设备:

Build for the simulator or the device?
     1. Device
     2. Simulator

Which would you like? [1]

第二步,选择目标代码格式:

Build type choices are:
     1. release
     2. debug

Which would you like? [1]

第三步,选择产品平台:

Product choices are:
     1. emulator
     2. generic
     3. sim
You can also type the name of a product if you know it.
Which would you like? [generic]

第四步,在选用参数下构建平台。

2. 独立模块的构件命令

  • 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.

其中mmm后面要跟模块的根目录,不是所有的目录下都有子模块,那些含有Android.mk文件目录才是模块的根目录,模块名可以从Android.mk的LOCAL_MODULE或者LOCAL_PACKAGE_NAME变量中得到。

单独编译某模块,需要在mmm后面指定模块路径,例如编译application中的Contacts:

mmm packages/apps/Contacts/

或者在src目录下直接运行make module name

cd ~/android/src
make Contacts

增量编译的步骤

1. 修改代码

2. 编译所修改的代码所在模块,例如:

cd ~/android/src
mmm packages/apps/Contacts

3. 在~/android/src中运行:

cd ~/android/src
make snod

该命令生成一个新的系统映像system.img

4.将这个系统映像拷贝至sdk下:

cd ~/android/src
cp out/target/product/generic/system.img \
   out/host/linux-x86/sdk/android-sdk_eng.justin_linux-x86/tools/lib/images/

5. 删除程序遗留的数据:

out/host/linux-x86/sdk/android-sdk_eng.justin_linux-x86/tools/emulator -wipe-data
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值