Android AOSP source code file structure and build system
To download Android source code please refer to Android page
AOSP directories
ART : ART is an acronym of Android RunTime and it has been introduced in the Android 4.4 Kitkat as an alternative to the Dalvik Virtual Machine. It has completely replaced Dalvik in Android 5.0 Lollipop. The old Dalvik VM was based on a Just-In-Time (JIT) compiler technology, that is, it interprets and compiles an application source code into machine code in real time. ART is based on an AOT (Ahead-of-time) technology, which compiles all the application code at the time of application installation, that is, before the execution. That obviously requires more time to install the application, but that time is usually imperceptible seeing the hardware performance of the latest Android devices.
bionic : Bionic is the C-runtime for Android.
build : This directory contains the whole Android build system. It contains all the makefile core templates. Besides that, it contains envsetup.sh, a script that allows the developer to work with Android sources without struggling with environment management.
external : All the packages regarding open source projects used by Android can be found in this directory. It contains various libraries as well as very important utilities such as zlib, SQLite, and webkit.
device : Here you can find all the configurations and definitions for specific devices.
frameworks : This folder is very important because it contains the source code for the Android framework. It is here that you can find all the main components of Android such as Activity, Services, and so on. Here you can also find the mapping used between the native code in C/C++ and the code in Java.
packages : As the folder name says, here you can find all the standard Android application packages, for example, Camera, Calculator, Dialer, Launcher, Settings, and so on.
system : The system/ directory contains the source code of the Android system core, that is a minimal Linux system that takes care of the initialization of the device before the ART virtual machine starts any Java-based service.
abi : This is the source file for libgabi++.
bootable: This includes the boot and startup related code.
cts: This directory contains the code for the compatibility test suite.
dalvik: This directory contains the code for the Dalvik virtual machine.
development: This directory contains development tools—the source code of the SDK and the NDK.
hardware: This folder contains HAL (Hardware Abstraction Layer), libraries that enable interfacing with the device hardware.
libcore: This directory contains Apache Harmony.
ndk: This directory contains the script to generate the Native Development Kit, that allows the use of the native code written in C/C++ from Android applications.
pdk: This is the Platform Development Kit, a set of utilities that Google sends to various OEMs so that they can update their own frameworks before important system updates
prebuilts: This directory contains precompiled files, including various toolchain versions.
sdk: This is the Software Development Kit.
tools: These are some external IDE tools.
Android build commnds
~$ . build/envsetup.sh
~$ lunch sdk-eng
~$ make
make –j8
The building system will fire up, looking for all those modules and Android.mk files to include into the build process and perform the compilation.
make –j8 showcommands
With this extra parameter, the build system will print all GCC compilation logs and all javaccompilation logs, to give you as much information as possible during the building process.
Building a module
make art
Cleaning a module
make clean-<module>
Cleaning everything
make clean
Listing modules
make modules
This command shows the list of every module available in the AOSP architecture.
make snod
This command recreates the system images, based on the current status of the source base, using an incremental building approach
make module_name snod
Building tools
make tools
Related :
The following command will create and provide us with two of the most important tools for an Android expert—adb and fastboot:
Fastboot
Fastboot is the tool that Android gives us to manipulate the device Flash Memory and its partitions, using a computer and an USB connection.
Fastboot does not communicate with the Android system. It communicates with a specific firmware able to interact in a minimal system environment: bootloader mode.
flash: This option is used to deploy a new binary system image from the host computer to the device partitions
erase: This option is used to delete a specific partition
reboot: This option is used to reboot the device in one of the available booting modes: recovery, bootloader, or standard
format: This option is used to format a specific partition
Creating a custom device
Let's create our own manufacturer and device folders:
mkdir –p device/irarref/f488
Android.mk: Describes in a generic way how to compile the source files.
AndroidProducts.mk: This file contains a PRODUCS_MAKEFILEs variable, with a list of all the available products.
full_f488.mk: This file specifies any relevant information about the device
BoardConfig.mk: This file specifies any relevant information about the device board.
vendorsetup.sh: This script makes the device available to envsetup.sh and lunch.
As we know, the so-called Recovery is a minimal runtime system, completely decoupled from the main Android system and totally self-sufficient. Its main goal is to guarantee system integrity and provide the necessary tools to fix common minor issues and restore a properly working system.
With an Android vanilla Recovery, we can:
- Update the Android system
- Wipe the data partition and the cache partition
The Android Recovery system is completely standalone. This means that whatever might happen to the main Android system, recovery will be always able to restore a working system.
To achieve this level of resilience, recovery contains its own Linux kernel and its own rootfs.
The Android Recovery system is completely standalone. This means that whatever might happen to the main Android system, recovery will be always able to restore a working system.
To achieve this level of resilience, recovery contains its own Linux kernel and its own rootfs.
Recovery mode can be accessed with a button combination when the device is turned off. The options you will find in the recovery menu could vary, but an Android vanilla recoverywill definitely provide these options:
- Reboot system now: This option will restart the system.
- Apply update from ADB: Android Debug Bridge can be used from a host computer to upload an official Google system update. Only certified updates can be uploaded and applied this way due to security measures enforced by the recovery to guarantee system integrity.
- Wipe cache partition: This option will erase the cache partition. This partition usually contains the system's temporary data and app cache data. Deleting this file will free quite an amount of disk space, without losing user data or apps.
- Wipe data/factory reset: This option will erase the volatile memory and restore the original factory system. Everything that is not strictly system-related will be deleted: videos, music, documents, user apps, and so on. The cache partition will be erased as well.
The most popular recovery alternatives are:
- Clockworkmod
- 4EXT
- Amon Ra Recovery
- Team Win Recovery Project (TWRP)
Please share your feedback about this blog. If you liked it please share with others
Related :