1. The Android build system
The Android Build System are described at https://android.googlesource.com/platform/build/+/master/core/build-system.html
You use build/envsetup.sh to setup a “convenience environment” for working on the Android source code. This should be source’ed into your current shell environment. After doing so you can type ‘help’ for a list of defined functions which are helpful for interacting with the source
The build system uses some pre-set environment variables and a series of ‘make’ files in order to build an Android system and prepare it for deployment to a platform.
Android make files end in the extension ‘.mk’ by convention, with the main make file in any particular source directory being named ‘Android.mk’.
There is only one official file named ‘Makefile’, at the top of the source tree for the whole repository. You set some environment variables, then type ‘make’ to build stuff. You can add some options to the make command line (other targets) to turn on verbose output, or perform different actions.
The build output is placed in ‘out/host’ and ‘out/target’ Stuff under ‘out/host’ are things compiled for your host platform (your desktop machine). Stuff under ‘out/target/product/<platform-name>’ eventually makes it’s way to a target device (or emulator).
The directory ‘out/target/product/<platform-name>/obj’ is used for staging “object” files, which are intermediate binary images used for building the final programs. Stuff that actually lands in the file system of the target is stored in the directories root, system, and data, under ‘out/target/product/<platform-name>’. Usually, these are bundled up into image files called system.img, ramdisk.img, and userdata.img.
This matches the separate file system partitions used on most Android devices.
2. Android application module build system
The build process involves many tools and process that convert your project into an Android Application Package – APK. The build process application module show as figure below
The general build process for a typical Android application module follow steps:
- The Android Asset Packaging Tool – aapt takes your application resource files, such as the AndroidManifest.xml file and the XML files for your activities, and compiles them. An R.java is also produced so you can reference your resources from your Java code.
- The aidl tool converts any .aidl interfaces that you have Java interface
- All of your Java code, including the R.java and .aidl files, are compiled by the Java compiler and .class files are output.
- The dex tool coverts the .class files to Dalvik byte code. Any 3rd party libraries and .class files that you have included in your project are also converted into .dex (Dalvik Executable) files so that they can be packaged into the final .apk file.
- All non-compiled resources (such as images), compiled resources, and the .dex files are sent to the apkbuilder tool to be packaged into an .apk file.
- Once the .apk is built, it must be signed with either a debug or release key before it can be installed to a device.
Finally, if the application is being signed in release mode, you must align the .apk with the zipaling tool. Aligning the final .apk decreases memory usage when the applications is running on a device.