Android 编译技巧

Android 编译技巧

在这里插入图片描述

Android 系统是基于 Linux 的,因此很多地方是相同的,比如编译。

Linux 中管理编译的文件是 Makefile,Android 系统管理编译的文件是 Android.mk,他们的语法相似,都会定义编译目标,声明依赖关系。

一般情况下,当你拿到了一个搭建好编译环境的 Android 源码,只需要在根目录执行

source build/envsetup.sh
lunch rk3399_mid-userdebug
make -j32

第一行是使能编译环境。第二行是你编译的版本,CPU型号 + userdebug、user、eng 等版本,第三行就是 make,多核编译。

这三行命令会使得 Android 系统全编译,第一次是肯定要全编译的。后面只修改几个文件,可以采用增量编译或者模块编译。

博主的电脑:i5-4210,16G 运行内存,500G 存储内存,第一次编译 Android8.1 耗时12小时。我的电脑编译 Linux 内核源码只要 18 分钟。

Android 模块编译

由于Android 全编耗时太久,大部分情况下,如果你只修改几个文件,可以模块编译。命令如下:

m:编译整个安卓系统

mm:编译当前目录下的模块,当前目录下需要有 Android.mk,否则就往上找最近的Android.mk文件。

mma:当前目录新增或删除文件后,可以用 mma 重新编译。

mmm:编译指定路径下的模块,指定的路径下面需要有 Android.mk

mmma:指定目录下新增或删除文件后,可以用mmma重新编译。

官方英文解释如下,来源于源码 build/envsetup.sh:

- m:         Makes from the top of the tree.
- mm:        Builds all of the modules in the current directory, but not their dependencies.
- mmm:       Builds all of the modules in the supplied directories, but not their dependencies.
             To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma:       Builds all of the modules in the current directory, and their dependencies.
- mmma:      Builds all of the modules in the supplied directories, and their dependencies.

如上编译后,并不会更新 /out/target/product/{project}/system.img 烧写镜像,还需要在根目录执行

make snod

重新进行打包,就会生成 system.img ,把 system.img 重新烧写到板子中就可以了。

Android 固件

不同厂商烧写的方式不一样,但大都是这几类文件。

Android 固件烧写工具一般命名为 AndroidTool.exe 或者 FlashTool.exe

** Android 系统的理解**

大家一般都是玩 Linux,完整的固件包括 uboot、Linux Kernel、rootfs。其实Android 就是把 rootfs 替换了,变成了 Android 文件系统,uboot 和 Linux Kernel 还是差不多的。

启动流程也是差不多的

最后

更多Android 学习资料以及面试题可以扫码免费领取!

Android基础课程资料包

目录

img

第一章 UI

img

第一章 UI

更有更多资料,加微信免费领取

img

img

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值