Copyright notice: This article is the blogger’s original article, shall not be reproduced without the permission of the blogger.

After downloading the Android source code project for the first time, we usually execute make command in the Android source code project directory, after a long wait, you can get the Android system image system.img. In the future, if we modify a module in the Android source code or add our own module to the Android source code project, will we still execute the make command? The answer is no, Google has prepared additional commands to support compiling individual modules, as well as repackaging the system.img command. Let’s take a look at this command before continuing with the Android source code.

Install the envsetup.sh script in the build directory of the Android source directory.

USER-NAME@MACHINE-NAME:~/Android$ . ./build/envsetup.sh

Note that this is a source command, and after execution, some additional commands can be used:

– 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.

The use of these commands can be seen by adding -help to the end of the command. Here we will focus on the MMM command, which can be used to compile all modules in a specified directory, usually containing only one module.

2. Use the MMM command to compile the specified module, such as the Email application:

USER-NAME@MACHINE-NAME:~/Android$ mmm packages/apps/Email/

Compilation is done, you can in the out/target/product/generic/system/app directory. See Email apk file. Android apps are stored in this directory. In addition, Android some executable file, for example, the C compiler executable file, put in the out/target/product/generic/system/bin directory, Dynamic link library files in the out/target/product/generic/system/lib directory, the out/target/product/generic/system/lib/hw directory to store the hardware abstraction layer (HAL) interface file, at the back of the article, We’ll be talking about it later, so stay tuned.

3. After compiling the module, we also need to repackage the system.img file so that when we run system.img on the simulator, we can see our program.

USER-NAME@MACHINE-NAME:~/Android$ make snod

4. Run the emulator as described in the article Downloading, compiling, and installing the latest Android source code on Ubuntu:

USER-NAME@MACHINE-NAME:~/Android$ emulator

And then we’re done.

Lao Luo’s Sina weibo: weibo.com/shengyanglu… , welcome to pay attention!