Android AOSP 单独编译某一模块

由于AOSP 项目太大,我只修改了一个模块,比如设置。
那么只需要单独编译设置这个模块就可以了。

首先执行Source:

source 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命令,也就是可以用它来编译指定目录的所有模块,通常这个目录只包含一个模块。

修改设置apk

设置apk 的项目在aosp/packages/apps/Settings下,我们在里面加上一个toast.

修改之后,lunch 一下

lunch 

然后指定自己编译的模块

接着,使用mmm命令来编译指定的模块,例如系统的设置应用程序:

// 编译设置模块
mmm packages/apps/Settings/
//将编译过得设置模块写到system.img里面去
make snod
//清楚数据启动模拟器
emulator -wipe-data

在这里插入图片描述

mmm packages/apps/Settings/ 编译完成之后,就可以在out/target/product/generic_x86_64/system/product/priv-app/Settings/Settings.apk目录下看到apk文件了。如上图

在这里插入图片描述

make snod 之后,就可以在out/target/product/generic_x86_64/system.img目录下看到img文件了。如上图

修改系统apk 之后的效果如下

我修改了系统的设置,每次onResume 就会弹出一个toast 。
在这里插入图片描述

我错了,上面说的方法不行。还是要重新编译一下System.img

我又尝试了下,简单的make snod 不会生效。
还是需要make -j8全部编译一下。

注意:

一定要emulator -wipe-data 否则你修改的内容可能不生效!我自己尝试了几次,才知道要这样做的!
网上没有人说要清楚数据。不知道他们都只是copy 别人的博客,还是怎么样。。。

原文地址:https://www.cnblogs.com/caoxinyu/p/10568479.html