您的位置:首页 > 移动开发 > Android开发

Ubuntu12.04下的Android 源码编译

2013-08-05 08:03 337 查看
(  环境配置请参考博文  Ubuntu12.04下的 Android 源码下载
)

Google官方资料参考 http://source.android.com/source/building-running.html
1. 环境设置,

下载好源码后,进入源码目录,即之前执行 repo sync的路径下,用下面两个命令之一,第二个命令简短一点,两个命令效果没区别

$ source build/envsetup.sh

$ . build/envsetup.sh


2.  选择编译的目标,用lunch指令,参数用来指定目标配置

$ lunch full-eng


参数形式是 BUILD-BUILDTYPE,其中 BUILD 是表明要合并的特殊特征的code name,下面是部分参数:

Build nameDeviceNotes
fullemulatorfully configured with all languages, apps, input methods
full_maguromaguro
full
build running on Galaxy Nexus GSM/HSPA+ ("maguro")
full_pandapanda
full
build running on PandaBoard ("panda")
 BUILDTYPE 可选下面参数:

BuildtypeUse
user限制访问;适合作为产品
userdebug类似 "user" 但可以有 root 访问权限和可调试;适用于调试设备
eng带有附加调试工具的开发配置
新手直接输入lunch,不带参数,会输出可选参数供你选择,类似下面这样

     1. aosp_arm-eng

     2. aosp_x86-eng

     3. aosp_mips-eng

     4. vbox_x86-eng

     5. full_maguro-userdebug

     6. full_toroplus-userdebug

     7. full_manta-userdebug

     8. full_toro-userdebug

     9. full_mako-userdebug

     10. full_panda-userdebug

     11. mini_mips-userdebug

     12. mini_armv7a_neon-userdebug

     13. mini_x86-userdebug

     14. full_arndale-userdebug

     15. aosp_flo-userdebug

     16. full_tilapia-userdebug

     17. full_grouper-userdebug

     18. aosp_deb-userdebug

3. 开始编译,make -j4

 参数 j 后数字可以用你系统支持线程数的1-2倍的值,比如你用双至强 E5520 (2个 CPU, 每个CPU 4核8线程),那最快的编译方式应该用参数 -j16或-j32。

执行后,报错 :/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc: 无法执行二进制文件

查了很久,确定是没有使用 64位Ubuntu造成,bt下载一个镜像,做个安装启动U盘搞定,地址很多,这儿推荐一个拥有很多bt资源的网址

安装后启动时发生了一点儿GRUB 错误,注意查看主板BIOS启动项,我那个华硕主板BIOS默认是WINDOWS系统方式,这造成了GRUB Error22。重新设置后可以正常启动。

4. 编译完成后,在 out/target/product/generics(或maguro或其他)目录下生成多个镜像文件及目录,可以运行模拟器加载这几个镜像文件

$ emulator -avd <有效AVD名称> -ramdisk [ramdisk.img路径] -system [system.img的路径]

不清楚AVD名称的话用下面命令查看

$ android list avd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息