编译Android平台以及SDK

完全编译

编译映像

cd ~/android/srcmake

映像编译成功后会在目录 ~/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/genericcd 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=genericTARGET_BUILD_VARIANT=engTARGET_SIMULATOR=TARGET_BUILD_TYPE=releaseTARGET_ARCH=armHOST_ARCH=x86HOST_OS=linuxHOST_BUILD_TYPE=releaseBUILD_ID=============================================Combining NOTICE files: out/target/product/generic/obj/NOTICE.txtFinding NOTICE files: out/host/linux-x86/obj/NOTICE_FILES/hash-timestampCombining NOTICE files: out/host/linux-x86/obj/NOTICE.txtPackage: out/target/product/generic/generic-img-eng.justin.zipSDK buildinfo: out/target/product/generic/sdk/sdk-build.propDocs droiddoc: out/target/common/docs/dxjavadoc: 错误 - 在 doclet 类 DroidDoc 中,方法 start 已抛出异常 java.lang.reflect.InvocationTargetExceptioncom.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 gdbclient 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 smoketest startviewserver stopviewserver tapas tracedmdump

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

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

tapas

第一步,选择目标设备:

Build for the simulator or the device?     1. Device     2. SimulatorWhich would you like? [1]

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

Build type choices are:     1. release     2. debugWhich would you like? [1]

第三步,选择产品平台:

Product choices are:     1. emulator     2. generic     3. simYou 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/srcmake Contacts

增量编译的步骤

1. 修改代码

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

cd ~/android/srcmmm packages/apps/Contacts

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

cd ~/android/srcmake snod

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

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

cd ~/android/srccp 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

更多相关文章

  1. Android(安卓)-HandleThread-给线程传参数
  2. Android(安卓)Screen Monitor抓取真机屏幕
  3. Android(安卓)命令行打包和签名
  4. FFmpeg 音频 调节音量 剪切 合成 拼接 视频命令
  5. Firebase引用版本冲突解决:Android(安卓)dependency 'com.google.
  6. linux android 下源码编译问题总结(一)
  7. 高德Demo,网上找了很多资料都不适合,自己研究出一个Demo,非常适合入
  8. Android(安卓)通过adb shell am broadcast发送广播
  9. android字符串处理(Mms模块短信内容解析)

随机推荐

  1. 详解如何通过反射获得枚举的Display中nam
  2. .net Elasticsearch入门实例详解
  3. C#简单工厂模式是什么?
  4. 分享一个“网红脸“”框架实例教程
  5. 本地是怎么配置iis调试的?
  6. 分享一些平时收藏和应用的开源代码
  7. pull总是提示输入密码问题是什么情况?
  8. 对wcf的理解--实现计算器功能
  9. 实现asp.net返回上一页有哪些实例?
  10. easyui怎么刷新当前tabs