Progress Β· 0/7 phases
ποΈ ποΈ Phase 2 β AOSP Architecture & Source Code
3 min read Β· Notion
Phase 2 β AOSP Architecture & Source Code
Duration: 3β4 weeks | Level: Intermediate
Understand the layered architecture of Android before diving into any single component.
ποΈ Android System Architecture (Layers)
ββββββββββββββββββββββββββββββββββββββββββββ
β Applications β β APKs (your apps)
ββββββββββββββββββββββββββββββββββββββββββββ€
β Application Framework β β Java APIs: AMS, WMS, PMS, etc.
ββββββββββββββββββββββββββββββββββββββββββββ€
β Native Libraries β Android Runtime β β C/C++ libs + ART/Dalvik
ββββββββββββββββββββββββββββββββββββββββββββ€
β Hardware Abstraction Layer β β HAL: camera, audio, sensors
ββββββββββββββββββββββββββββββββββββββββββββ€
β Linux Kernel β β Drivers, memory, power
ββββββββββββββββββββββββββββββββββββββββββββAndroid is built in layers. Each layer only communicates with the layer directly below it through well-defined interfaces.
ποΈ Build System: Soong + Make
Android's build system has two components:
Android.mk (legacy Make)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello_world
LOCAL_SRC_FILES := hello.cpp
include $(BUILD_EXECUTABLE)Android.bp (Soong β modern)
cc_binary {
name: "hello_world",
srcs: ["hello.cpp"],
shared_libs: ["liblog"],
}Soong uses Blueprint language. Most new modules use .bp. Key build rules:
cc_binary,cc_library_shared,cc_library_staticβ C/C++ targetsjava_library,android_appβ Java/app targetshidl_interface,aidl_interfaceβ IPC interface definitions
π¦ Key Directories Deep Dive
frameworks/base/
The heart of the Android Framework. Read these:
frameworks/base/
βββ core/java/android/ # Public Android APIs
βββ services/core/java/ # System services (AMS, WMS, PMS)
βββ core/jni/ # JNI bridge to native code
βββ cmds/ # System command-line toolssystem/core/
Low-level system daemons:
system/core/
βββ init/ # Android init process (PID 1)
βββ adb/ # ADB daemon
βββ fastboot/ # Fastboot protocol
βββ libutils/ # Base utility librarieshardware/interfaces/
HIDL/AIDL HAL interface definitions:
hardware/interfaces/
βββ audio/
βββ camera/
βββ sensors/
βββ wifi/π Reading AOSP Source Code
How to find anything fast
# Find all files with a class name
find . -name "ActivityManagerService.java"
# grep with context
grep -rn "startActivity" frameworks/base/services/core/ --include="*.java" | head -30
# Use cs.android.com (best for navigation)Key source files to read first
| File | Why |
|---|---|
system/core/init/main.cpp | Entry point of Android userspace |
frameworks/base/core/java/android/app/ActivityThread.java | App process main loop |
frameworks/base/services/core/java/com/android/server/SystemServer.java | Launches all system services |
frameworks/base/core/java/android/os/Binder.java | IPC base class |
build/soong/Android.bp | Build system entry |
π§© Android Runtime (ART)
ART replaced Dalvik in Android 5.0+.
- AOT compilation: On install,
.dexbytecode β native machine code viadex2oat - JIT compilation: At runtime, hot paths get JIT compiled
- Garbage Collection: Concurrent, generational GC
- Profile-guided optimization (PGO): After first run, frequently-used paths get AOT compiled
Key ART files: art/runtime/, art/compiler/
π οΈ Hands-On Tasks
-
Add a log line to
SystemServer.javaand rebuild framework only:mmm frameworks/base/services adb sync system adb reboot -
Add a new
cc_binaryhello world using Soong (Android.bp), build and push to emulator. -
Explore
ActivityThread.javaβ find whereonCreate()is called. -
Read
SystemServer.javaβ list all services started instartOtherServices().
β Phase 2 Checklist
- Can explain all 5 layers of Android architecture
- Understand Soong build system (
Android.bp) - Can build a single module (
mmm) - Know top-level dirs:
frameworks/,system/,hardware/,art/ - Read
SystemServer.javaand listed all started services - Read
ActivityThread.javaβ understand app main loop - Added a custom
Android.bpmodule and built it - Can use
cs.android.comfor code navigation - Understand what ART does vs Dalvik