资源预览内容
第1页 / 共9页
第2页 / 共9页
第3页 / 共9页
第4页 / 共9页
第5页 / 共9页
第6页 / 共9页
第7页 / 共9页
第8页 / 共9页
第9页 / 共9页
亲,该文档总共9页全部预览完了,如果喜欢就下载吧!
资源描述
Android源码编译与调试整理:Joey Yin如有任何问题,请联系yzy9508hotmail.com系统环境ubuntu-11.10-desktop-i386onVMware Workstation 8.0.0 build-471780onWindowsXP源码编译软件环境基本按照http:/source.android.com/source/initializing.html,未设置ccache。下载源码http:/source.android.com/source/downloading.html,版本:android-4.0.3_r1下载3、4天的时间才最终完成。编译make j4出现错误,发现ubuntu-11.10默认安装的是gcc4.6,但编译android需要gcc4.4。重新安装gcc4.4后执行 make j4,顺利完成编译。执行emulator出现错误,发现是由于之前安装了android sdk的缘故。在 /.bashrc中将android sdk的路径从PATH中移除,同时增加:export ANDROID_PRODUCT_OUT=/home/joeyyin/android_4.0.3_r1/out/target/product/genericexport ANDROID_PRODUCT_OUT_BIN=/home/joeyyin/android_4.0.3_r1/out/host/linux-x86/binexport PATH=$ANDROID_PRODUCT_OUT:$ANDROID_PRODUCT_OUT_BIN:$PATH编译生成的emulator等其他bin工具在/home/joeyyin/android_4.0.3_r1/out/host/linux-x86/bin目录。System.img, userdata.img, ramdis.img在/home/joeyyin/android_4.0.3_r1/out/target/product/generic其中Ramdisk.img是emulator的文件系统。System.img包括主要的包、库等文件。Userdata.img包括了一些用户数据,emulator负责加载3个映像文件后,会把system.img,userdata.img分别加载到ramdisk文件系统的system和userdata目录下。再执行emulator,模拟器顺利启动。cd /android_4.0.3_r1/out/target/product/genericemulator -system system.img -data userdata.img -ramdisk ramdisk.img编译模块android中的一个应用程序可以单独编译,编译后要重新生成system.img在源码目录下执行$ . 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.可以加help查看用法我们可以使用mmm来编译指定目录的模块,如编译联系人:$ mmm packages/apps/Browsers/编完之后生成两个文件:out/target/product/generic/data/app/Browser.apkout/target/product/generic/system/app/Browser.apk可以使用$ make snod重新生成system.img,再运行模拟器编译SDK$make sdk悲剧的出现以下错误:解决:查找alarmprovider模块,没有发现搜索build目录下含alarmprovider的项目去掉这两个文件中的PRODUCT_PACKAGES中alarmprovider。网上也有关于这个问题的解答:“Indeed there is no a module with name AlarmProvider in the source tree now.To fix it, remove AlarmProvider from the product definition in thefollowing files:./build/target/product/large_emu_hw.mk:25: AlarmProvider./build/target/product/generic_no_telephony.mk:24: AlarmProvider“$ make sdk又先后出现和以上类似的针对Sync, Updater, SyncProvider, 看了网上的信息,也可以使用 make PRODUCT-sdk-sdk进行编译将generic_no_telephony.mk, large_emu_hw.mk恢复$ make PRODUCT-sdk-sdk半小时候顺利完成编译。make SDK和make PRODUCT -sdk-sdk有何异同?编译后生成的SDK存放在out/host/linux-x86/sdk/,此目录下有android-sdk_eng.joeyyin_linux- x86.zip和android-sdk_eng.joeyyin_linux-x86目录。android-sdk_eng.joeyyin_linux-x86就是 SDK目录实际上,当用mmm命令编译模块时,一样会把SDK的输出文件清除,因此,最好把android-sdk_eng.joeyyin_linux-x86移出来此后的应用开发,就在该SDK上进行,所以把在/.bashrc中增加sdk tools/platform_tools到PATH中:export ANDROID_SDK_HOME=/home/joeyyin/android_4.0.3_r1/out/host/linux-x86/sdk/android-sdk_eng.joeyyin_linux-x86export PATH=$ANDROID_SDK_HOME/tools:$ANDROID_SDK_HOME/platform_tools: $PATH创建Android Virtual Device编译出来的SDK是没有AVD(Android Virtual Device)的,我们可以通过android工具查看:$ android list创建AVD:$ android create avd -t 1 -n myavd可以android help来查看上面命令选项的用法。创建中有一些选项,默认就行了再执行android list,可以看到AVD存放的位置以后每次运行emulator都要加-avd myavd或myavd选项:$ emulator -avd myavd源码编译分析首先需要理解makefile的编写规则推荐一篇介绍文章http:/www.cnblogs.com/dskit/archive/2010/02/09/1666771.html。Makefile - build/core/main.mkEclipse+adtEclipse 安装下载eclipse from http:/www.eclipse.org/downloads/?osType=linux这个版本在后面编译安装adt时会有错误,建议下载下面的版本:$ tar zxvf eclipse-jee-indigo-SR2-linux-gtk.tar.gz$ tar zxvf eclipse-SDK-3.7.2-linux-gtk.tar.gz$ sudo mv eclipse /opt$ cd /opt$ sudo chown -R root:root eclipse$ sudo chmod -R +r eclipse$ sudo touch /usr/bin/eclipse$ sudo chmod 755 /usr/bin/eclipse$ sudo vim /usr/bin/eclipse文件内容如下:#!/bin/sh#export MOZILLA_FIVE_HOME=/usr/lib/mozilla/export ECLIPSE_HOME=/opt/eclipse$ECLIPSE_HOME/eclipse $*$ sudo vim /usr/share/applications/eclipse.desktop文件内容如下:Desktop EntryEncoding=UTF-8Name=EclipseComment=Eclipse IDEExec=eclipseIcon=/opt/eclipse/icon.xpmTerminal=falseType=ApplicationCategories=GNOME;Application;Development;StartupNotify=trueStart eclipse firsttime:$ /opt/eclipse/eclipse -clean &编译安装adt$ cd /android_4.0.3_r1/out/host/linux-x86$ mkdir adt$ cd /android_4.0.3_r1/sdk/eclipse/scripts$ export ECLIPSE_HOME=/opt/eclipse$ ./build_server.sh /android_4.0.3_r1/out/host/linux-x86/adt处理失败,出现很多类似以下依赖错误,据说要下载安装JavaEE版eclipse。Missing required plug-in com.android.ide.eclipse.adt_0.0.0.直接启动eclipse - help -install new software -add - https:/dl-ssl.google.com/android/eclipse/天煞的,这个地址居然无法连接【难道又被天朝封了?】下载javaee版本eclipse安装后,重新编译adt成功。运行eclipse$ eclipsehelp -install new software
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号