Android Architecture


Android Architecture Interview with follow-up questions

1. Can you explain the architecture of Android?

Android's architecture is layered, with each layer building on the one below it. Understanding this stack is important because it explains where your application code runs and how it interacts with device hardware.

The layers from bottom to top

1. Linux Kernel The foundation of Android. Provides hardware abstraction, process and memory management, the security model (each app runs as a unique Linux user), the file system, and device drivers (camera, display, Bluetooth, Wi-Fi). Android's security sandbox relies directly on Linux process isolation and user IDs.

2. Hardware Abstraction Layer (HAL) Sits between the Linux kernel and the Android framework. Defines standard interfaces that hardware manufacturers implement for each component (camera HAL, audio HAL, sensors HAL, etc.). This allows the Android framework to call standardized APIs without knowing the specifics of any vendor's hardware. Android 8+ restructured HALs into HIDL (HAL Interface Definition Language) and later AIDL-based binderized HALs for better stability and update independence.

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

  • Native libraries (Bionic libc, OpenGL ES, SQLite, WebKit/Blink) provide core capabilities used by the framework and exposed to apps via the NDK.
  • Android Runtime (ART) executes compiled app bytecode (DEX format) using ahead-of-time compilation with profile-guided optimization. Replaced the old Dalvik VM starting in Android 5.0 Lollipop.

4. Java API Framework (Android Framework) The set of APIs that app developers call directly: Activity Manager, Window Manager, Content Providers, View System, Package Manager, Notification Manager, Location Manager, etc. Written in Java/Kotlin and runs on ART.

5. System Apps + User Apps At the top sit the built-in system apps (dialer, settings, contacts) and user-installed apps. All apps run in their own sandboxed process on ART.

Project Treble and Mainline

Android 8 introduced Project Treble to separate the vendor implementation (HAL, kernel) from the Android framework, allowing OEMs to deliver Android OS updates without waiting for chipset vendors to update their HALs. Android 10+ added Project Mainline, which pushes security and bug-fix updates to framework modules (DNS resolver, media codecs, permission controller) directly through the Google Play Store without a full OTA update.

Interviewer follow-up: "Where does Binder fit?" Binder is Android's IPC (inter-process communication) mechanism, implemented as a kernel driver. It underpins most framework service calls — when your app calls getSystemService(Context.LOCATION_SERVICE), it is making a Binder IPC call to the system server process. It is high-performance, type-safe, and enforces security via UID checking at the kernel level.

↑ Back to top

Follow-up 1

What is the role of the Linux Kernel in Android architecture?

The Linux Kernel is the foundation of the Android architecture. It provides the necessary hardware abstraction, memory management, process management, and device drivers. It acts as an interface between the hardware and the rest of the software stack. The Linux Kernel handles tasks such as managing the file system, network stack, power management, and security. It also provides support for various hardware components such as display, camera, audio, and input devices.

Follow-up 2

What is the function of Android Runtime?

The Android Runtime includes the core libraries and the Dalvik Virtual Machine (DVM) or the Android Runtime (ART). The DVM is responsible for running the Android applications. It executes the bytecode generated by the Java compiler and converts it into machine code that can be executed by the device's processor. The DVM uses Just-In-Time (JIT) compilation to improve the performance of the applications.

In Android 4.4 KitKat, the ART was introduced as the default runtime. ART uses Ahead-Of-Time (AOT) compilation, which pre-compiles the bytecode into machine code during the app installation process. This eliminates the need for JIT compilation at runtime and improves the overall performance of the applications.

Follow-up 3

Can you explain the Libraries layer in Android architecture?

The Libraries layer in the Android architecture contains a set of libraries that provide various functionalities to the Android system. These libraries include:

  • Surface Manager: Manages the display surfaces and compositing of windows.
  • Media Framework: Provides multimedia capabilities such as audio and video playback, recording, and streaming.
  • SQLite: A lightweight relational database management system used for data storage.
  • WebKit: A web browser engine used for rendering web pages.
  • OpenGL ES: A graphics library for rendering 2D and 3D graphics.
  • SSL/TLS: Provides secure communication over the network.

These libraries are used by the Android system and applications to access and utilize different features and services.

Follow-up 4

What is the purpose of the Application Framework in Android architecture?

The Application Framework in the Android architecture provides a set of reusable components and services that developers can use to build applications. It includes various APIs and frameworks that simplify the development process and provide access to system resources and functionalities.

Some of the key components of the Application Framework include:

  • Activity Manager: Manages the lifecycle of applications and activities.
  • Content Providers: Allows applications to share data with other applications.
  • Resource Manager: Handles access to non-code resources such as strings, images, and layouts.
  • Notification Manager: Allows applications to display notifications to the user.
  • Location Manager: Provides access to location-based services.

The Application Framework acts as an abstraction layer between the underlying system and the applications, making it easier for developers to create rich and interactive Android applications.

Follow-up 5

How does the Applications layer interact with other layers in Android architecture?

The Applications layer in the Android architecture interacts with other layers through the various APIs and frameworks provided by the Application Framework.

When an application is launched, the Activity Manager in the Application Framework manages its lifecycle and starts the necessary components. The application can then utilize the libraries and services provided by the Libraries layer to access system functionalities such as multimedia playback, database storage, web browsing, and more.

The Applications layer can also interact with the Linux Kernel layer through system calls and device drivers. For example, an application can use the camera API to capture photos or the network API to make network requests.

Overall, the Applications layer relies on the underlying layers of the Android architecture to provide the necessary infrastructure and services for the applications to run and interact with the device's hardware and software resources.

2. What is the Dalvik Virtual Machine and how does it work?

The Dalvik Virtual Machine (DVM) was the original managed runtime used by Android from its first release until Android 4.4 KitKat (2013), where it was offered alongside the new Android Runtime (ART). Dalvik was fully replaced by ART in Android 5.0 Lollipop (2014). It is no longer present in modern Android, so this is a historical question — but understanding it helps explain why ART was designed the way it is.

How Dalvik worked

  • Android apps are written in Kotlin or Java and compiled to Java bytecode (.class files).
  • The build toolchain then cross-compiled .class files into DEX (Dalvik Executable) bytecode using the dx tool (now replaced by D8 and R8). DEX is a more compact format designed for memory-constrained mobile devices — multiple .class files are merged into one .dex file with a shared constant pool.
  • At runtime, Dalvik used Just-In-Time (JIT) compilation: it interpreted DEX bytecode and selectively compiled frequently executed ("hot") code paths into native machine code on the fly, caching the compiled code in memory.

Dalvik's design constraints

Dalvik was designed for devices with 256 MB to 512 MB of RAM and relatively slow storage. It used a register-based instruction set rather than Java's stack-based bytecode, which reduced instruction count per operation. Each app ran in its own DVM instance, forked from Zygote (which preloaded common classes).

Limitations that led to ART's creation

  • JIT compilation happened at every launch — no compiled code persisted across reboots, so startup was slow.
  • JIT compilation consumed CPU time and memory during app execution.
  • The garbage collector caused noticeable pauses ("jank") on the UI thread.
  • The 64K method reference limit per DEX file (the "multidex problem") required workarounds in large apps.

Why it matters today

Knowing Dalvik's limitations explains why ART's ahead-of-time compilation was such an improvement, and why the DEX format is still in use today (ART still compiles DEX, just differently). The term "APK" (Android Package) contains a classes.dex file to this day, now optimized by the D8 compiler and further minimized by R8.

↑ Back to top

Follow-up 1

How does Dalvik Virtual Machine differ from Java Virtual Machine?

The Dalvik Virtual Machine (DVM) and the Java Virtual Machine (JVM) are both virtual machines, but they have some key differences:

  1. Architecture: The DVM is specifically designed for mobile devices and uses a register-based architecture, while the JVM is designed for general-purpose computing and uses a stack-based architecture.

  2. Bytecode Format: The DVM executes bytecode files in the .dex format, which are optimized for mobile devices, while the JVM executes bytecode files in the .class format, which are generated from Java source code.

  3. Memory Management: The DVM uses a garbage collector optimized for mobile devices, while the JVM uses a garbage collector optimized for general-purpose computing.

  4. Execution Model: The DVM uses just-in-time (JIT) compilation to convert bytecode into machine code at runtime, while the JVM uses either just-in-time (JIT) compilation or ahead-of-time (AOT) compilation.

Overall, the DVM is optimized for mobile devices with limited resources, while the JVM is optimized for general-purpose computing.

Follow-up 2

What is the role of .dex files in Dalvik Virtual Machine?

In the Dalvik Virtual Machine (DVM), .dex files play a crucial role. .dex stands for Dalvik Executable, and it is the file format used to store the compiled bytecode of Android applications. During the build process, Java source code is compiled into .class files, and then these .class files are converted into .dex files using the dx tool. The .dex files contain the bytecode instructions that the DVM can execute. By using .dex files, the DVM can optimize the memory usage and reduce the storage footprint of Android applications, making them more suitable for mobile devices with limited resources.

Follow-up 3

Why was Dalvik Virtual Machine replaced by Android Runtime?

The Dalvik Virtual Machine (DVM) was replaced by Android Runtime (ART) in Android 5.0 (Lollipop) for several reasons:

  1. Performance: ART introduced ahead-of-time (AOT) compilation, which compiles the bytecode into machine code during the app installation process. This eliminates the need for just-in-time (JIT) compilation at runtime, resulting in faster app startup times and smoother overall performance.

  2. Memory Efficiency: ART uses a more efficient garbage collector and memory management system compared to the DVM, resulting in reduced memory usage and improved battery life.

  3. Developer Productivity: ART provides improved debugging and profiling tools for developers, making it easier to optimize and troubleshoot Android applications.

Overall, the switch from DVM to ART was aimed at improving the performance, efficiency, and developer experience of Android applications.

Follow-up 4

What are the advantages and disadvantages of Dalvik Virtual Machine?

Advantages of the Dalvik Virtual Machine (DVM):

  1. Memory Efficiency: The DVM is designed to optimize memory usage, making it suitable for mobile devices with limited resources.

  2. Just-in-Time (JIT) Compilation: The DVM uses JIT compilation to convert bytecode into machine code at runtime, which allows for efficient execution on resource-constrained devices.

  3. Garbage Collection: The DVM uses a garbage collector optimized for mobile devices, which helps manage memory efficiently.

Disadvantages of the DVM:

  1. Performance: The JIT compilation process in the DVM can introduce some overhead, resulting in slower app startup times compared to ahead-of-time (AOT) compilation.

  2. Limited Language Support: The DVM primarily supports Java and does not have full support for other programming languages.

  3. Deprecated: The DVM has been replaced by Android Runtime (ART) in newer versions of Android, so it is no longer actively developed or supported.

3. What is Android Runtime and how does it improve upon the Dalvik Virtual Machine?

Android Runtime (ART) is the managed runtime that executes Android applications. It replaced Dalvik starting with Android 5.0 Lollipop (2014) and has been continuously improved through Android 15.

Key improvements over Dalvik

1. Ahead-of-Time (AOT) compilation Dalvik compiled bytecode to native code on-the-fly at runtime (JIT). ART introduced AOT compilation: when an app is installed (or on first boot), DEX bytecode is compiled to native machine code and stored on device. This eliminated the JIT startup overhead and improved execution speed.

2. Hybrid compilation strategy (Android 7+) Pure AOT turned out to have its own tradeoffs — install time was slow and compiled code occupied significant storage. Android 7 Nougat introduced a hybrid model still in use today:

  • Profile-guided compilation (PGC): JIT collects a profile of which methods are "hot" during actual use. The system compiles only those hot methods to native code during idle/charging time.
  • AOT for hot code: the resulting profile-optimized native code is stored, giving best-of-both-worlds startup and execution performance.
  • Baseline Profiles: developers can ship a pre-built profile with their app (via the profileinstaller library) so that critical code paths are AOT-compiled from the first install, reducing cold start time by 30–40%.

3. Improved garbage collection ART replaced Dalvik's stop-the-world GC with concurrent, compacting collectors that do most of their work without pausing the main thread. Android 8+ introduced a moving GC that also compacts the heap, reducing memory fragmentation and improving memory efficiency.

4. Better debugging and profiling ART provides richer support for JDWP (Java Debug Wire Protocol), and tools like Android Studio's profilers (CPU, memory, network) are built on ART's profiling capabilities. Method tracing, allocation tracking, and heap dumps are first-class features.

5. 64-bit support ART fully supports 64-bit ABIs (arm64-v8a, x86_64). Dalvik was 32-bit only. Google Play required 64-bit support since 2019.

D8 and R8

The compiler toolchain has also evolved. The old dx converter is replaced by D8 (faster, produces smaller DEX) and R8 (combined shrinker, obfuscator, and DEX compiler that replaces ProGuard + D8). R8 produces smaller APKs and enables better dead code elimination and inlining at the bytecode level.

Practical implication for developers

Understanding ART's profile-guided compilation is directly relevant to optimizing app startup. Shipping a Baseline Profile in a library or app (generated via generateBaselineProfile Gradle task) and using Macrobenchmark to measure it is now a standard performance practice for production Android apps.

↑ Back to top

Follow-up 1

What is the role of Ahead-of-Time (AOT) compilation in Android Runtime?

Ahead-of-Time (AOT) compilation is a key feature of Android Runtime (ART). It involves compiling the bytecode of an app into native machine code before it is run. This is in contrast to the Dalvik Virtual Machine (DVM), which used Just-in-Time (JIT) compilation.

AOT compilation offers several advantages:

  1. Faster Startup Times: Since the app's code is already compiled into native machine code, there is no need for the runtime to spend time on JIT compilation during app startup. This results in faster startup times for apps.

  2. Improved Performance: By compiling the bytecode ahead of time, ART can optimize the code more effectively, resulting in improved overall performance.

  3. Reduced Memory Usage: AOT compilation allows for better memory management, as the compiled code takes up less memory compared to the bytecode.

Overall, AOT compilation plays a crucial role in enhancing the performance and efficiency of Android apps.

Follow-up 2

How does garbage collection work in Android Runtime?

Garbage collection in Android Runtime (ART) is the process of automatically reclaiming memory that is no longer in use by an app. ART uses a garbage collector called the Concurrent Mark Sweep (CMS) collector, which works in the following steps:

  1. Marking: The CMS collector starts by marking all objects that are still in use. It traverses the object graph, starting from the roots (such as static variables and active threads), and marks all reachable objects.

  2. Concurrent Sweep: While the marking phase is happening, the CMS collector concurrently sweeps through the memory, freeing up memory occupied by objects that are no longer in use. This allows the app to continue running without significant pauses.

  3. Concurrent Mark: After the sweep phase, the CMS collector performs a concurrent marking phase to identify any objects that were missed during the initial marking phase.

Overall, the CMS collector in ART improves garbage collection performance by reducing pauses and allowing the app to maintain smooth performance even during garbage collection.

Follow-up 3

What are the advantages and disadvantages of Android Runtime?

Android Runtime (ART) offers several advantages over the previous Dalvik Virtual Machine (DVM):

  1. Improved Performance: ART's Ahead-of-Time (AOT) compilation and enhanced garbage collection result in improved app performance, faster startup times, and reduced memory usage.

  2. Better Debugging and Profiling: ART provides better debugging and profiling tools compared to the DVM, making it easier for developers to analyze and optimize their apps.

  3. Compatibility: ART is backward-compatible with apps that were developed for the DVM, ensuring that existing apps can run on newer Android versions.

However, there are also some disadvantages of ART:

  1. Increased Storage Space: AOT compilation requires the compiled code to be stored on the device, which can increase the storage space required by apps.

  2. Increased Installation Time: Since the bytecode is compiled into native machine code during installation, the installation time of apps can be longer compared to the DVM.

Despite these disadvantages, the overall performance and efficiency improvements of ART make it a preferred choice for Android app development.

Follow-up 4

How does Android Runtime affect app performance?

Android Runtime (ART) has a significant impact on app performance. It improves performance in the following ways:

  1. Faster Startup Times: ART's Ahead-of-Time (AOT) compilation eliminates the need for Just-in-Time (JIT) compilation during app startup, resulting in faster startup times.

  2. Improved Overall Performance: AOT compilation allows ART to optimize the code more effectively, resulting in improved overall performance of the app.

  3. Reduced Garbage Collection Pauses: ART's Concurrent Mark Sweep (CMS) garbage collector reduces pauses caused by garbage collection, allowing the app to maintain smooth performance even during memory management.

However, there are some factors that can affect app performance with ART:

  1. Increased Storage Space: AOT compilation requires the compiled code to be stored on the device, which can increase the storage space required by apps.

  2. Increased Installation Time: Since the bytecode is compiled into native machine code during installation, the installation time of apps can be longer compared to the previous Dalvik Virtual Machine (DVM).

Overall, ART significantly improves app performance by reducing startup times, optimizing code, and improving memory management.

4. Can you explain the concept of Zygote in Android architecture?

Zygote is a special system process that acts as the parent of all Android application processes. Understanding it explains how Android achieves fast app launch times and efficient memory sharing.

What Zygote does

When the Android system boots, the init process starts the Zygote process early in the boot sequence. Zygote performs expensive initialization work once:

  1. It starts the ART (Android Runtime) virtual machine.
  2. It preloads a large set of common Java/Kotlin classes from the Android framework into its heap (roughly 5,000–10,000 classes depending on the Android version).
  3. It preloads common resources (themes, drawables) that most apps will need.

After this initialization, Zygote listens on a Unix domain socket for requests from the Activity Manager to spawn new app processes.

How new app processes are created

When the user launches an app, the Activity Manager sends a fork request to Zygote. Zygote calls fork(), which creates a copy-on-write duplicate of the Zygote process. The forked child process:

  • Already has ART initialized.
  • Already has the common framework classes loaded and available in memory.
  • Is then specialized by loading the app's own DEX code and setting up the app's Application class.

Why this is efficient

The fork() system call uses copy-on-write (CoW) semantics: the child process shares the parent's memory pages until it needs to modify them. Because all apps share the same preloaded classes and ART heap from Zygote, those pages are never modified and are physically shared in RAM. This means preloading 50 MB of framework classes in Zygote costs ~50 MB total, not 50 MB × (number of running apps).

WebView Zygote

Android also has a separate webview_zygote process that preloads the WebView rendering engine. This is isolated from the app Zygote to contain the WebView renderer in a more restricted sandbox (for security).

Practical implication

You cannot meaningfully reduce the time Zygote takes because it happens before your app is launched. However, reducing what your own Application.onCreate() does (deferring heavy initialization, using lazy singletons with Hilt) directly reduces the perceived cold start time after Zygote has forked your process.

↑ Back to top

Follow-up 1

What is the role of Zygote in process creation?

Zygote is responsible for creating new app processes in Android. It acts as a template process that is forked to create new processes. When an app is launched, Zygote is used to create a new process for that app.

The role of Zygote in process creation includes:

  1. Loading essential system classes and libraries into memory.
  2. Preloading common resources, such as system resources and frameworks, to reduce startup time.
  3. Sharing these preloaded resources among multiple app processes to conserve memory.

By using Zygote as a template, the Android system can create new app processes quickly and efficiently.

Follow-up 2

How does Zygote contribute to resource sharing?

Zygote contributes to resource sharing in Android by preloading common resources, such as system classes and libraries, into memory. These preloaded resources are then shared among multiple app processes, which helps in conserving memory.

When Zygote is created during the Android system startup, it loads essential system resources and frameworks into memory. These resources are then available to all the app processes that are created from Zygote.

By sharing these preloaded resources, Android avoids the need for each app process to load the same resources individually. This reduces memory usage and improves overall system performance.

Follow-up 3

What is the fork system call and how is it related to Zygote?

The fork system call is a mechanism in operating systems that creates a new process by duplicating the existing process. It creates a copy of the existing process, known as the child process, which is an exact replica of the parent process.

In the context of Android, Zygote uses the fork system call to create new app processes. When Zygote is started, it loads essential system resources and frameworks into memory. It then forks itself to create new app processes. The child processes created by forking Zygote inherit the preloaded resources, which helps in reducing the startup time and conserving memory.

By using the fork system call, Zygote efficiently creates new app processes in Android.

Follow-up 4

How does Zygote affect app startup time?

Zygote plays a significant role in reducing app startup time in Android. It achieves this by preloading common resources, such as system classes and libraries, into memory. When a new app process is created from Zygote, it can directly use these preloaded resources, which eliminates the need for loading them again.

By sharing preloaded resources among multiple app processes, Zygote avoids redundant loading of the same resources. This results in faster app startup times as the app processes can start executing immediately without waiting for resource loading.

Overall, Zygote's contribution to resource sharing and preloading significantly improves app startup time in Android.

5. What is the role of the Hardware Abstraction Layer (HAL) in Android architecture?

The Hardware Abstraction Layer (HAL) is a software layer in Android's architecture that sits between the Android framework and device-specific hardware drivers in the Linux kernel. Its primary purpose is to allow the Android framework to work with diverse hardware from different manufacturers without knowing the specifics of any particular implementation.

The problem HAL solves

Android runs on hardware from hundreds of different manufacturers — Qualcomm, MediaTek, Samsung, Google, and others — each with their own camera, audio, GPS, and sensor implementations. Without an abstraction layer, the Android framework would need to be rewritten for each vendor's hardware. Instead, Google defines a standard HAL interface for each hardware component. Manufacturers implement that interface in their proprietary drivers. The Android framework calls the interface; it never cares which vendor is behind it.

Structure

Each hardware subsystem has its own HAL module:

  • Camera HAL (Camera2 framework calls down to camera HAL)
  • Audio HAL
  • Bluetooth HAL
  • Sensors HAL
  • Gralloc HAL (graphics memory allocation)
  • and many more

HIDL and AIDL HALs (Android 8+)

Before Android 8 (Oreo), HALs were shared libraries loaded directly into the system server process. This meant a HAL crash could crash the entire system server. Android 8 introduced Project Treble, which restructured HALs into binderized HALs using HIDL (HAL Interface Definition Language). With binderized HALs, each HAL runs in its own process. A crash in a camera HAL process no longer brings down the rest of the system.

From Android 11+, the industry is migrating from HIDL to AIDL-based HALs, which reuse the same Interface Definition Language as Android's application-layer IPC, simplifying the toolchain.

Why Project Treble matters

Project Treble's separation of the vendor partition (containing HAL implementations) from the system partition (containing the Android framework) means that Google and OEMs can update the Android framework without requiring chipset vendors to update their HAL implementations first. This directly enabled faster Android OS updates reaching devices.

Developer relevance

App developers rarely interact with HALs directly. You access hardware through high-level Android framework APIs (Camera2, AudioRecord, SensorManager). The HAL is the reason those APIs work consistently across vastly different devices — it is the contract between the Android platform and the hardware ecosystem.

↑ Back to top

Follow-up 1

What is the purpose of HAL interfaces?

The purpose of HAL interfaces is to define a set of methods and data structures that the Android framework can use to communicate with specific hardware components. Each hardware component has its own HAL interface, which defines the functions and data structures required to interact with that component. These interfaces allow the Android framework to access and control the hardware in a standardized way, regardless of the specific implementation of the hardware.

Follow-up 2

How does HAL interact with the Linux Kernel?

HAL interacts with the Linux Kernel through device drivers. The Linux Kernel provides a set of device drivers that are responsible for managing the hardware components. HAL uses these device drivers to communicate with the hardware and abstracts the low-level details, providing a consistent interface for the Android framework.

Follow-up 3

How does HAL contribute to device compatibility?

HAL contributes to device compatibility by abstracting the hardware details and providing a standardized interface for the Android framework. This allows application developers to write code that can work across different devices, regardless of the specific hardware implementation. By providing a consistent API, HAL ensures that applications can access and utilize the hardware features in a uniform manner, improving compatibility and reducing the need for device-specific code.

Follow-up 4

What are some examples of hardware components abstracted by HAL?

HAL abstracts various hardware components in an Android device, including but not limited to:

  • Camera: HAL provides an interface for accessing and controlling the camera hardware.
  • Audio: HAL abstracts the audio hardware, allowing the Android framework to play and record audio.
  • Sensors: HAL provides access to various sensors such as accelerometer, gyroscope, and proximity sensor.
  • Display: HAL allows the Android framework to control the display hardware, including screen resolution, brightness, and orientation.
  • Bluetooth: HAL abstracts the Bluetooth hardware, enabling communication with other Bluetooth devices.

These are just a few examples, and HAL can abstract many other hardware components depending on the device.

Live mock interview

Mock interview: Android Architecture

Intermediate ~5 min Your own free AI key

Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.