Android Architecture

From Linux Kernel to your app — understand every layer of the Android software stack

Linux Kernel ART Framework Apps

Table of Contents

Architecture Overview

Android architecture is a layered software stack built on the Linux kernel. Each layer provides abstractions to the layer above it, so app developers work with high-level APIs while the system handles hardware, memory, and security underneath.

From bottom to top, the stack is: Linux KernelHardware Abstraction Layer (HAL)Native Libraries + Android Runtime (ART)Application FrameworkApplications.

Bottom layers
Hardware, drivers, security
Middle layers
Runtime, native C/C++ libs
Top layers
Framework APIs + your apps

1Linux Kernel

The Linux Kernel is the foundation of Android. It sits directly on top of the physical hardware and provides core OS services that all upper layers depend on.

Device Drivers

Display, camera, audio, Wi-Fi, Bluetooth, GPS, sensors — kernel drivers talk to hardware chips.

Memory Management

Allocates RAM to processes, handles paging, and prevents apps from accessing each other's memory.

Power Management

CPU sleep states, wake locks, and battery optimization at the system level.

Process Isolation

Each app runs in its own Linux process with a unique UID — sandboxing starts here.

Kernel responsibilityWhy it matters for developers
Process schedulingMultitasking — many apps appear to run simultaneously
Network stack (TCP/IP)All HTTP, WebSocket, and socket APIs ultimately use kernel networking
File system (ext4, F2FS)App private storage, shared media, and cache directories
IPC (Binder driver)Enables inter-process communication between app and system services
Why Linux?

Google chose Linux for its proven security model, mature driver ecosystem, and open-source license. Android adds custom kernel patches (Binder, Ashmem, wakelocks) on top of standard Linux.

2Android Runtime (ART)

The Android Runtime (ART) executes your app's bytecode. Since Android 5.0 (Lollipop), ART replaced the older Dalvik VM, delivering significantly better performance and battery efficiency.

How ART works

1

Your Kotlin/Java code is compiled to .class files, then converted to DEX (Dalvik Executable) bytecode.

2

At install time, ART performs AOT (Ahead-of-Time) compilation — DEX is compiled to native machine code on the device.

3

At runtime, ART also uses JIT (Just-in-Time) for hot code paths — frequently used methods get further optimized.

4

Garbage Collection (GC) reclaims unused memory automatically — ART's concurrent GC reduces UI jank.

FeatureDalvik (legacy)ART (current)
CompilationJIT only at runtimeAOT at install + JIT at runtime
App startupSlower (interpret bytecode)Faster (pre-compiled native code)
BatteryMore CPU for interpretationLess runtime overhead
File format.dex.dex (same), stored in APK/AAB
Build pipeline — source to DEX# Gradle compiles Kotlin → .class → .dex during build ./gradlew assembleDebug # DEX files end up inside the APK: # classes.dex, classes2.dex (for multidex apps) # View DEX info with Android SDK tool d8 --version

3Application Framework

The Application Framework exposes high-level Java/Kotlin APIs that developers use daily. It manages app lifecycle, UI, data, and system services through a set of Manager classes and Content Providers.

Manager / APIResponsibility
Activity ManagerLaunches Activities, manages back stack, app lifecycle
Window ManagerScreen layout, dialogs, system UI overlays
Package ManagerInstall/uninstall apps, resolve intents, permissions
Notification ManagerPost and manage status bar notifications
Location ManagerGPS and network-based location
Telephony ManagerPhone calls, SIM info, network type
Content ProvidersShared data access — Contacts, MediaStore, Settings
View SystemWidgets, layouts, drawing, touch events
Kotlin — Framework API usage examples// Activity Manager — start another Activity startActivity(Intent(this, SecondActivity::class.java)) // Notification Manager — post a notification val nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager nm.notify(1, notification) // Package Manager — check if app is installed val pm = packageManager val installed = pm.getLaunchIntentForPackage("com.example.app") != null
Jetpack: Modern Android libraries (Room, ViewModel, Navigation, WorkManager) sit on top of the framework and are the recommended way to build production apps today.

4Libraries

Below the Application Framework sit Native Libraries (C/C++) and the Hardware Abstraction Layer (HAL). These provide performance-critical and hardware-specific functionality without exposing kernel details to upper layers.

Native Libraries (C/C++)

SQLite

Embedded database engine — used by Room and ContentProviders.

OpenGL ES / Vulkan

2D/3D graphics rendering for games and custom views.

MediaCodec

Hardware-accelerated audio/video encode and decode.

FreeType / Skia

Font rendering and 2D graphics drawing engine.

Hardware Abstraction Layer (HAL)

HAL defines standard interfaces for hardware vendors. OEMs implement HAL modules for their specific chips while Android's framework calls the same API regardless of device.

HAL moduleHardware controlled
Camera HALCamera sensors, autofocus, flash
Audio HALSpeakers, microphones, Bluetooth audio
Graphics HALGPU composition and display output
Sensors HALAccelerometer, gyroscope, fingerprint
Radio HALCellular modem, Wi-Fi, NFC

NDK — calling native code from your app

Kotlin — JNI bridge to C/C++ (NDK)class NativeLib { // Load native .so library compiled via Android NDK external fun stringFromJNI(): String companion object { init { System.loadLibrary("native-lib") } } } // Usage in Activity: // textView.text = NativeLib().stringFromJNI()

5App Layers

The top layer — Applications — is where your code lives. Android apps are built from four component types, all running inside isolated sandboxes (separate Linux processes).

Activity Service Broadcast Receiver Content Provider
System Apps

Pre-installed with the OS — Phone, Settings, Camera, Contacts. Run with elevated privileges.

User Apps

Downloaded from Play Store or sideloaded — Instagram, banking apps, games. Sandboxed by default.

Library Apps (AAR)

Reusable code packaged as Android Archive — Firebase SDK, Retrofit, Glide.

Process & sandbox model

1

Each app gets its own Linux process and unique UID (user ID).

2

Apps cannot read each other's private data unless permission is granted.

3

Components communicate via Intents and Binder IPC — never direct memory access.

4

When memory is low, Android kills background processes — apps must save state in onSaveInstanceState.

Layer (top to bottom)What you interact with
Your App (Kotlin/Java)Activities, ViewModels, Compose UI, business logic
Jetpack / Support LibrariesRoom, Navigation, LiveData, WorkManager
Android Framework APIsActivity Manager, Package Manager, Notifications
ART + Native LibsBytecode execution, SQLite, OpenGL, MediaCodec
HAL + KernelHardware drivers, memory, security (invisible to most devs)

6Android Architecture Diagram

The complete Android software stack from hardware to applications. Data and API calls flow downward through layers; hardware events flow upward.

Data flow example — tapping a button

5. Your Activity's onClick listener runs (Kotlin code)
4. View System dispatches touch event via Framework
3. ART executes compiled bytecode for event handler
2. Input HAL + kernel touch driver capture finger press
1. Touchscreen hardware sends coordinates to kernel

Key takeaway: As an Android developer, you primarily work at the Application and Application Framework layers. Understanding the full stack helps you debug performance issues, write efficient native code (NDK), and answer architecture questions in interviews. Next: dive into Activities & Intents — the building blocks of every Android screen.

Android Architecture MCQ Practice

10 Basic MCQs 10 Advanced MCQs

10 Basic Android Architecture MCQs

1

Bottom layer of Android stack?

ALinux Kernel
BApplications
CART only
DPlay Store
Explanation: Linux kernel handles drivers, power, memory, and process management.
2

ART replaced which runtime?

ADalvik
BJVM desktop
CNode
D.NET
Explanation: ART (Android Runtime) superseded Dalvik from Lollipop onward.
3

HAL stands for?

AHardware Abstraction Layer
BHyper Application Loader
CHost Access Library
DHigh API Level
Explanation: HAL interfaces between kernel drivers and framework.
4

Application layer contains?

ASystem and user apps
BOnly Linux shell
CGPU firmware only
DGradle scripts
Explanation: Apps sit atop the framework using SDK APIs.
5

Native C/C++ libraries used for?

APerformance-critical code (media, graphics)
BOnly manifests
CPlay billing only
DEmulator settings
Explanation: NDK allows native code for games, codecs, and heavy computation.
6

System Server runs in?

ASeparate process hosting framework services
BEach app process
CKernel ring 0 only
DBrowser
Explanation: ActivityManager, PackageManager, etc. run in system_server.
7

Binder IPC is used for?

ACross-process communication
BLayout inflation only
CGradle sync
DPNG compression
Explanation: Binder enables secure RPC between app and system services.
8

Zygote process?

AForks new app processes with preloaded classes
BCompiles Kotlin
CStores photos
DADB daemon
Explanation: Zygote preloads common classes to speed app startup via copy-on-write.
9

Framework APIs are written mainly in?

AJava/Kotlin accessible SDK
BAssembly only
CSQL
DHTML
Explanation: Developers call Java/Kotlin framework classes (Activity, View, etc.).
10

SurfaceFlinger relates to?

ACompositing graphics to display
BDatabase indexing
CNetwork DNS
DAudio MIDI
Explanation: SurfaceFlinger combines surfaces from apps for the screen.

10 Advanced Android Architecture MCQs

11

AOT vs JIT in ART?

AAOT compile at install; JIT at runtime — ART uses hybrid
BSame
CNeither used
DOnly Dalvik JIT
Explanation: ART optimizes with profile-guided compilation over time.
12

SELinux on Android provides?

AMandatory access control isolating processes
BUI theming
CAPK signing
DLayout preview
Explanation: SELinux enforces security policies per process/domain.
13

System apps vs user apps?

ASystem apps pre-installed with elevated privileges possible
BNo difference
CUser apps run in kernel
DSystem apps skip ART
Explanation: System apps may use signature permissions; user apps are sandboxed normally.
14

Ashmem/ION relate to?

AShared memory for graphics/buffers
BGradle daemon
CManifest merge
DLint checks
Explanation: Low-level memory allocators feed graphics pipeline.
15

PackageManagerService role?

AInstall/uninstall/query packages
BDraw UI widgets
CPlay music only
DCompile XML layouts
Explanation: PM parses manifests, manages permissions and component resolution.
16

ActivityManagerService?

AManages Activity stack and process lifecycle
BBuilds Gradle
CStores contacts only
DEmulator GPU
Explanation: AMS decides when Activities start, pause, or processes die.
17

Treble project improved?

AVendor/system separation for faster updates
BRemoved Linux
CBanned Kotlin
DMerged iOS
Explanation: Project Treble standardized HAL/vendor interfaces for OEM updates.
18

Main thread in app process also called?

AUI thread
BBinder thread
CRender thread only
DZygote main
Explanation: UI updates and touch must run on main thread.
19

Sandbox per app means?

AUnique UID, isolated data directory
BShared /data for all apps
CKernel module per app
DNo permissions ever
Explanation: Each app runs as separate Linux UID with private storage.
20

HWComposer role?

AHardware-assisted display composition
BJava garbage collector
CAPK zipalign
DSQLite WAL
Explanation: HWC can compose layers in display hardware reducing GPU load.
Click an option to select, then check answers.

Android Architecture Interview Q&A

15 topic-focused questions for interviews and revision.

1List the main layers of Android architecture top to bottom.easy
Answer: Applications → Application Framework → Native Libraries + ART → HAL → Linux Kernel.
2What does the Linux kernel do on Android?easy
Answer: Drivers, power management, memory, networking, process scheduling — same core as Linux adapted for mobile.
3Explain ART's role.medium
Answer: ART executes dex bytecode, manages GC, JIT/AOT compilation, and provides core runtime support for apps.
4What is the Application Framework?easy
Answer: Java/Kotlin APIs (Activity, ContentResolver, LocationManager) wrapping system services for app developers.
5Why native libraries exist alongside ART.medium
Answer: Performance and reuse of C/C++ stacks for graphics (OpenGL/Vulkan), media codecs, SQLite, etc.
6How does an app communicate with system services?hard
Answer: Through Binder IPC — proxy objects in app process talk to real implementations in system_server.
7What is Zygote and why is it important?hard
Answer: Zygote preloads classes and forks new app processes quickly with copy-on-write memory sharing.
8Difference between AOSP and Google Mobile Services.medium
Answer: AOSP is open-source Android base; GMS adds proprietary Google apps and APIs (Maps, FCM) requiring licensing.
9What is HAL and give an example.medium
Answer: Hardware Abstraction Layer — e.g., camera HAL lets framework talk to vendor-specific camera drivers uniformly.
10Explain app sandbox security model.medium
Answer: Each app has unique Linux user ID, private storage, must request permissions for protected data and hardware.
11What runs in the system_server process?hard
Answer: Core services: ActivityManager, PackageManager, WindowManager, PowerManager, etc.
12How does SurfaceFlinger relate to what users see?hard
Answer: It composites layers (status bar, app, nav bar) into the final framebuffer sent to display.
13Project Treble benefit for users.medium
Answer: Faster Android version updates by decoupling vendor HAL implementation from Android OS framework.
14Main thread vs background work principle.easy
Answer: Never block UI thread; network/DB on background threads or coroutines; UI updates back on main.
15Compare Dalvik vs ART briefly.medium
Answer: Dalvik JIT-only, per-app dex; ART ahead-of-time/profile-guided, better performance and battery.