Skip to content

Android - Architecture

The Android operating system is a sophisticated stack of software components. This stack can be broadly divided into five main sections, typically visualized in layers. Understanding this architecture is crucial for developing robust and efficient Android applications.

The main layers of the Android architecture, from bottom to top, are:

  1. Linux Kernel
  2. Hardware Abstraction Layer (HAL)
  3. Native C/C++ Libraries and Android Runtime (ART)
  4. Java API Framework (Application Framework)
  5. System Apps and User Applications

At the base of the Android platform lies the Linux Kernel. Android is built on top of a Long-Term Support (LTS) version of the Linux kernel, modified with specific enhancements for mobile devices. The kernel is responsible for:

  • Hardware Drivers: Manages low-level device hardware such as display, camera, Wi-Fi, Bluetooth, USB, audio, and keypad.
  • Process Management: Handles application processes, allocating resources and ensuring isolation.
  • Memory Management: Manages system RAM and virtual memory.
  • Networking Stack: Provides TCP/IP networking capabilities.
  • Security: Enforces security measures like user-based permissions and sandboxing of applications.

The kernel provides a level of abstraction between the device hardware and the rest of the software stack.

The Hardware Abstraction Layer (HAL) provides a standard interface that exposes device hardware capabilities to the higher-level Java API framework. HALs consist of multiple library modules, each implementing an interface for a specific type of hardware component, such as the camera or Bluetooth module.

When a framework API makes a call to access device hardware, the Android system loads the library module for that hardware component. This allows Android to be agnostic about lower-level driver implementations, making it more portable across different hardware configurations.

3. Native C/C++ Libraries and Android Runtime (ART)

Section titled “3. Native C/C++ Libraries and Android Runtime (ART)”

This layer sits on top of the HAL and Linux Kernel and provides core functionalities for the Android system. It consists of two main sub-components:

Many core Android system components and services are built from native code (C and C++) that require native libraries. These libraries are exposed to developers through the Java API framework. Key native libraries include:

  • Bionic (libc): A custom C library optimized for Android.
  • Media Frameworks: Libraries like MediaCodec, Stagefright (older), and libav for playback and recording of various audio and video formats.
  • SurfaceFlinger: Manages display and composes graphic buffers from multiple applications onto the screen.
  • Skia: A 2D graphics rendering engine used for drawing UI elements.
  • OpenGL ES & Vulkan: APIs for high-performance 2D and 3D graphics rendering.
  • SQLite: A lightweight relational database engine used for local data storage.
  • WebKit/Blink: The web rendering engine that powers WebView.
  • SSL/TLS (e.g., BoringSSL): For secure internet communication.

Android applications, primarily written in Kotlin or Java, run on the Android Runtime (ART). ART replaced the older Dalvik Virtual Machine (DVM) in Android 5.0 (Lollipop). Key features of ART include:

  • Ahead-Of-Time (AOT) Compilation: Compiles app bytecode (Dalvik Executable - DEX files) into native machine code upon app installation, improving runtime performance and battery life.
  • Just-In-Time (JIT) Compilation: Complements AOT by further optimizing frequently executed code paths at runtime.
  • Optimized Garbage Collection (GC): More efficient memory management compared to Dalvik.
  • Improved Debugging Support: Better diagnostics and profiling capabilities.

Each Android application runs in its own process with its own instance of ART, ensuring app isolation and stability. ART and its core libraries provide the runtime environment for executing app code and managing system resources.

4. Java API Framework (Application Framework)

Section titled “4. Java API Framework (Application Framework)”

This layer provides the high-level Java (and Kotlin-callable) APIs that developers use to build Android applications. It consists of a rich set of classes and services that abstract the complexity of the underlying layers. Key components of the Application Framework include:

  • Activity Manager: Manages the lifecycle of activities and the activity stack (back stack).
  • View System: Provides the fundamental UI building blocks (Views and ViewGroups) for creating user interfaces. This includes widgets like buttons, lists, text fields, and layout managers. Modern UI development also uses Jetpack Compose, a declarative UI toolkit built with Kotlin.
  • Notification Manager: Allows apps to display custom alerts and notifications to the user.
  • Resource Manager: Provides access to non-code resources such as strings, layouts, drawables, and other assets.
  • Content Providers: Enable applications to share data with other applications in a structured and secure manner.
  • Package Manager: Manages installed applications and their metadata.
  • Telephony Manager: Provides access to telephony services (calls, SMS).
  • Location Manager: Provides access to location services (GPS, network-based location).
  • WindowManager: Manages windows and their display on the screen.

Developers interact primarily with this framework, leveraging Android Jetpack libraries which are a suite of libraries, tools, and guidance to help developers follow best practices, reduce boilerplate code, and write code that works consistently across Android versions and devices. Jetpack components often provide enhanced or simpler APIs over the base framework classes (e.g., Room for database, ViewModel for UI-related data, Navigation for app navigation).

At the top layer are the applications themselves. This includes:

  • System Apps: Pre-installed applications that provide core device functionality, such as the Phone dialer, Contacts, Browser, Email client, Camera, and Settings app.
  • User Applications: Applications installed by the user from Google Play Store or other sources. These are the apps that developers create using the Android SDK and Java API Framework.

All applications, whether system or user-installed, utilize the services and APIs provided by the lower layers of the Android architecture. This layered architecture promotes modularity, security, and allows for a rich ecosystem of applications on a wide variety of hardware.