Sunday, January 20, 2013

The android build system keeps a clean seperation of source and output. All intermediates and final output are placed in the directory named out. So, the simple way to fully clean a build is deleting the out directory.
The hierarchy of the out directory is shown below:

Under the out/target/product/generic/obj directory, there are several subdirectories, APPS, EXECUTABLES, SHARED_LIBRARIES, STATIC_LIBRARIES. They contain build output for modules of different type, java application, native executable, shared libraries and static libraries, respectively. Under the module type's directory, there is a directory for each module of corresponding type, named with the module's name catenating _intermediates. So, when we need to clean a specific module, we can simply delete the intermediate directory for the module.
For example, in the Android.mk for stlport, there is a LOCAL_MODULE defined as libstlport, which is a shared library (by including $(BUILD_SHARED_LIBRARY)). The output of this module will be placed in SHARED_LIBRARIES/libstlport_intermediates directory. The linker will generate the final shared library in the SHARED_LIBRARIES/libstlport_intermediates/LINKED directory.
After a module has been compiled the linked, it's to be stripped and copied to directory for creating file system image. The build system doesn't perform stripping in place. Instead, it will first copy the file with debugging symbol information (the file under LINKED directory) to correct place in symbols directory. Then strip the file and save in intermediate directory (for executable) or obj/lib directory (for shared library), meanwhile, the file without symbol and the file with symbol are associated with 'objcopy --add-gnu-debuglink' command. Finally, the stripped file will be copied to system directory.
Once all modules are built, the system directory should have been populated with necessary files. The build system will create three file system images, ramdisk.img, userdata.img, and system.img with system, root and data as source directories respectively. The default choice of file system is yaffs2.