SoFunction
Updated on 2025-04-04

Implementation method for compiling modules in Android source code separately

After downloading the Android source code project for the first time, we usually execute the make command in the Android source code project directory. After a long wait, we can get the Android system image. In the future, if we modify a module in the Android source code or add a new module to the Android source code project, should we still execute the make command? The answer is no, Google has prepared additional commands for us to support compiling separate modules and repackaging commands. Before continuing to learn Android source code, let's take a look at this command first.

      1. First, there is a script file in the build directory under the Android source code directory. After executing this script file, you can obtain some useful tools:

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

      Notice:This is a source command. After execution, there will be some additional commands available:

 - 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 specific usage of these commands can be viewed with -help after the command. Here we only focus on the mmm command, that is, we can use it to compile all modules in the specified directory. Usually this directory only contains one module.

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

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

After compilation is completed, you can see the file in the out/target/product/generic/system/app directory. All apps that come with Android are placed in this directory. In addition, some executable files of the Android system, such as C compiled executable files, are placed in the out/target/product/generic/system/bin directory, the dynamic link library files are placed in the out/target/product/generic/system/lib directory, and the out/target/product/generic/system/lib/hw directory stores hardware abstraction layer (HAL) interface files. We will mention them in the following articles, so please pay attention.

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

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

     4. Run the emulator according to the method introduced in the article downloading, compiling and installing the latest Android source code on Ubuntu:

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

This way everything is done.

I hope it will be helpful to those who study Android source code!