← back to blog
April 28, 2025

AOSP Architecture, Build System & Boot Process: Technical Notes

AOSPAndroidBuild SystemAndroid ArchitectureBoot Process

§Android Architecture: The Complete Stack

Each layer of Android's architecture serves a distinct role in the overall system:

┌────────────────────────────────────────────────────┐
│               Application Layer                    │
│    ┌────────────────┐    ┌───────────────────┐     │
│    │  System Apps   │    │  Third-party Apps │     │
│    └────────────────┘    └───────────────────┘     │
├────────────────────────────────────────────────────┤
│         Application Framework Layer                │
│  ┌──────────────────────────────────────────────┐  │
│  │ Activity   Package   Window    Telephony     │  │
│  │ Manager    Manager   Manager   Manager       │  │
│  │                                              │  │
│  │ Location   Resource  Content   View          │  │
│  │ Manager    Manager   Providers System        │  │
│  └──────────────────────────────────────────────┘  │
├────────────────────────────────────────────────────┤
│       Libraries & Android Runtime Layer            │
│  ┌────────────────────┐   ┌─────────────────────┐  │
│  │   C/C++ Libraries  │   │   Android Runtime   │  │
│  │                    │   │                     │  │
│  │ • WebKit           │   │ • ART (AOT)         │  │
│  │ • OpenMAX AL       │   │ • Core Libraries    │  │
│  │ • libc             │   │ • JIT Compiler      │  │
│  │ • OpenGL|ES        │   │ • Memory Mgmt       │  │
│  │ • Media Framework  │   │                     │  │
│  │ • SQLite           │   │                     │  │
│  │ • SSL              │   │                     │  │
│  └────────────────────┘   └─────────────────────┘  │
├────────────────────────────────────────────────────┤
│        Hardware Abstraction Layer (HAL)            │
│  ┌──────────────────────────────────────────────┐  │
│  │ Audio HAL | Camera HAL | Sensors HAL | etc.  │  │
│  └──────────────────────────────────────────────┘  │
├────────────────────────────────────────────────────┤
│               Linux Kernel                         │
│  ┌──────────────────────────────────────────────┐  │
│  │ Drivers | Memory Mgmt | Process Mgmt | I/O   │  │
│  └──────────────────────────────────────────────┘  │
└────────────────────────────────────────────────────┘

§The AOSP Build System: Evolution from Make to Soong

Android's build system has evolved to handle the complexity of building the entire Android system:

                    Build System Evolution
┌─────────────┐    ┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│ Android.mk  │    │    Make     │    │    Kati     │    │    Ninja    │
│  (Legacy)   │──► │ (GNU Make)  │──► │ (Makefile   │──► │ (Build Tool)│
└─────────────┘    └─────────────┘    │   Parser)   │    └─────────────┘
                                      └─────────────┘           │
                                                                ▼
                                                         ┌─────────────┐
                                                         │   Output    │
                                                         │   (.img)    │
                                                         └─────────────┘

                    Modern Soong System
┌─────────────┐    ┌──────────────┐    ┌─────────────┐
│  Blueprint  │    │    Soong     │    │    Ninja    │
│ (.bp files) │──► │ (Go program) │──► │ Build Files │
└─────────────┘    └──────────────┘    └─────────────┘

§Advanced Build Commands

bash
# Initialize environment
source build/envsetup.sh

# View all available commands
hmm

# Select build target
lunch aosp_arm64-eng
bash
# Build entire system
m

# Build specific module and dependencies
mma

# Build all modules in current directory
mm

# Build all modules in current directory with dependencies
mma

# Build specific modules
mmm packages/apps/Settings packages/apps/Launcher3

# Build specific modules with dependencies
mmma packages/apps/Settings frameworks/base

# Incremental builds
m -j8  # Use 8 threads
m -k   # Keep going when some targets fail
bash
# Search commands
cgrep "pattern"    # Search in C/C++ files
jgrep "pattern"    # Search in Java files
resgrep "pattern"  # Search in resource XML files
mangrep "pattern"  # Search in AndroidManifest.xml files
sepgrep "pattern"  # Search in SEPolicy files
sgrep "pattern"    # Search in all source files

# Module navigation
godir filename      # Go to directory containing a file
gomod module_name   # Go to module directory
pathmod module_name # Print module path
refreshmod          # Refresh module database
allmod              # List all modules
bash
# Analyze build performance
m showcommands    # Show actual commands executed
m dist            # Create distribution package
m checkbuild      # Run build system checks
m modules         # List all defined modules

# Clean builds
m clean-<module>  # Clean specific module
m installclean    # Clean installed files
m clobber         # Complete clean (removes out/)

§AOSP Source Code Deep Dive

AOSP Root
│
├── art/              ── Android Runtime (ART)
│   ├── compiler/     ── AOT/JIT compilers
│   ├── runtime/      ── Runtime components
│   └── dex2oat/      ── DEX to OAT converter
│
├── bionic/           ── Android's C library
│   ├── libc/         ── Core C library
│   ├── libm/         ── Math library
│   └── linker/       ── Dynamic linker
│
├── frameworks/       ── Core system services
│   ├── base/         ── Framework APIs
│   │   ├── core/java/android/
│   │   ├── services/core/
│   │   └── native/
│   └── av/           ── Audio/Video framework
│
├── system/           ── Core OS components
│   ├── core/         ── Init, logd, etc.
│   ├── sepolicy/     ── SELinux policies
│   └── vold/         ── Volume daemon
│
└── hardware/         ── HAL implementations
    ├── interfaces/   ── HAL interfaces (HIDL)
    └── libhardware/  ── Legacy HAL

§Android Boot Process

[Power On] ──► [Bootloader] ──► [Kernel] ──► [Init] ──► [Zygote] ──► [System Server] ──► [System UI]
    │               │              │           │          │               │               │
    │               │              │           │          │               │               │
 Hardware       Load Kernel     Hardware      Mount FS   Create        Start          UI Components
 Init           Check           Init &        SELinux    Android       System         Status Bar
 PMU            Hardware        Drivers       Policies   Runtime       Services       Navigation
                Load                                     (ART)         (AMS,PMS)      Launcher
                Recovery

§System Server Services Startup

startBootstrapServices()    startCoreServices()         startOtherServices()
         │                        │                           │
         ▼                        ▼                           ▼
  - Installer              - BatteryService          - CameraService
  - ActivityManager        - UsageStatsService       - AlarmManager
  - PowerManager           - WebViewUpdateService    - InputManager
  - DisplayManager         - GpuService              - WindowManager
  - PackageManager                                   - BluetoothService
  - SensorService                                    - AudioService
                                                     - NotificationManager

§Advanced Build Configuration

makefile
# device/<vendor>/<device>/device.mk
PRODUCT_NAME := aosp_device
PRODUCT_DEVICE := device
PRODUCT_BRAND := vendor
PRODUCT_MODEL := Device Name
PRODUCT_MANUFACTURER := Vendor

# Include device-specific configurations
$(call inherit-product, device/vendor/device/device-common.mk)

# Device-specific overlays
DEVICE_PACKAGE_OVERLAYS += device/vendor/device/overlay
makefile
# device/<vendor>/<device>/BoardConfig.mk
TARGET_ARCH := arm64
TARGET_CPU_ABI := arm64-v8a
TARGET_CPU_VARIANT := cortex-a53

# Kernel configuration
TARGET_KERNEL_SOURCE := kernel/vendor/device
TARGET_KERNEL_CONFIG := device_defconfig

# Partitions
BOARD_BOOTIMAGE_PARTITION_SIZE := 67108864
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 3221225472

§Runtime Resource Overlays (RRO)

Base Resource Tree         Overlay Configuration         Final Runtime View
       │                             │                            │
┌────────────────┐          ┌─────────────────┐          ┌────────────────┐
│ res/           │          │ overlay/        │          │ Merged View    │
│ ├── values/    │    +     │ └── res/        │    =     │ ├── values/    │
│ ├── layout/    │          │     └── values/ │          │ ├── layout/    │
│ └── drawable/  │          │         └── ..  │          │ └── drawable/  │
└────────────────┘          └─────────────────┘          └────────────────┘

§Build System Performance Optimization

bash
# Use ccache for C/C++ compilation
export USE_CCACHE=1
export CCACHE_DIR=/path/to/ccache
prebuilts/misc/linux-x86/ccache/ccache -M 50G
bash
# Only rebuild changed modules
m installclean && m

# Use all available cores
m -j$(nproc)

# Build only what you need
mmm frameworks/base/services

§Advanced Development Workflow

[Code Change] ──► [Build Module] ──► [Test] ──► [Debug] ──► [Submit]
      │                 │               │          │            │
  git status         mm/mma         atest       logcat      repo upload
  git add           make test       CTS/VTS    debuggerd    gerrit review
  git commit                                   systrace
April 28, 2025← all posts