0
0
Android Kotlinmobile~15 mins

Android architecture overview (Linux kernel, ART, framework) in Android Kotlin - Deep Dive

Choose your learning style9 modes available
Overview - Android architecture overview (Linux kernel, ART, framework)
What is it?
Android architecture is the way Android's software is organized to make apps run smoothly on devices. It has layers, starting from the Linux kernel at the bottom, which handles hardware and core system tasks. Above that is the Android Runtime (ART), which runs app code efficiently. On top is the Android framework, which provides tools and building blocks for app developers.
Why it matters
Without this layered architecture, apps would struggle to work on different devices and hardware. It solves the problem of making apps run fast, safely, and consistently across many phones and tablets. This structure also helps developers build apps without worrying about low-level hardware details.
Where it fits
Before learning this, you should understand basic programming and what an operating system does. After this, you can learn how to build Android apps using Kotlin and how to use Android's APIs effectively.
Mental Model
Core Idea
Android architecture is a layered system where each layer builds on the one below to manage hardware, run apps, and provide tools for app creation.
Think of it like...
Think of Android architecture like a restaurant kitchen: the Linux kernel is the kitchen staff handling the basic cooking tools and appliances, ART is the chef who prepares the dishes efficiently, and the framework is the recipe book that guides how to make each dish.
┌─────────────────────────────┐
│      Android Framework       │  ← Tools and APIs for apps
├─────────────────────────────┤
│       Android Runtime (ART)  │  ← Runs app code efficiently
├─────────────────────────────┤
│         Linux Kernel         │  ← Manages hardware and core system
└─────────────────────────────┘
Build-Up - 6 Steps
1
FoundationUnderstanding the Linux Kernel Role
🤔
Concept: The Linux kernel is the base layer that controls hardware and system resources.
The Linux kernel is like the brain of the device's operating system. It talks directly to the hardware like the screen, camera, and memory. It manages processes, security, and communication between hardware and software.
Result
You see how Android can work on many devices because the kernel handles hardware differences.
Understanding the kernel helps you see how Android controls the device's physical parts safely and efficiently.
2
FoundationWhat is Android Runtime (ART)?
🤔
Concept: ART is the environment where Android apps run their code.
ART takes the app's code and turns it into instructions the device can execute quickly. It replaces the older Dalvik runtime and improves speed and battery life by compiling code ahead of time.
Result
Apps start faster and run smoother because ART prepares their code efficiently.
Knowing ART explains why apps perform well and how Android manages app execution.
3
IntermediateExploring the Android Framework Layer
🤔
Concept: The framework provides ready-made tools and APIs for building apps.
This layer offers components like buttons, notifications, and data storage. Developers use these tools to create app features without building everything from scratch. It also manages app lifecycles and user interactions.
Result
Developers can build apps faster and with consistent behavior across devices.
Recognizing the framework's role shows how Android simplifies app development.
4
IntermediateHow Layers Communicate in Android
🤔Before reading on: do you think the app talks directly to hardware or through layers? Commit to your answer.
Concept: Each layer interacts only with the layer directly below or above it to keep the system organized.
Apps use the framework APIs, which then use ART to run code, and ART relies on the kernel to access hardware. This separation keeps apps safe and the system stable.
Result
Apps cannot accidentally harm hardware or other apps because of this controlled communication.
Understanding this layered communication explains Android's security and stability.
5
AdvancedART Ahead-of-Time Compilation Benefits
🤔Before reading on: do you think compiling app code before running it is faster or slower? Commit to your answer.
Concept: ART compiles app code ahead of time to improve performance and battery life.
Instead of translating code while the app runs, ART compiles it once when the app installs. This reduces delays during app use and saves power.
Result
Apps launch faster and use less battery compared to older methods.
Knowing ART's compilation method reveals why modern Android devices feel responsive.
6
ExpertLinux Kernel Customizations for Android
🤔Before reading on: do you think Android uses a plain Linux kernel or a customized one? Commit to your answer.
Concept: Android uses a Linux kernel customized with special features for mobile devices.
Google adds modules for power management, security (like SELinux), and hardware drivers specific to phones. These changes optimize battery life and protect user data.
Result
Android devices run efficiently and securely on diverse hardware.
Understanding kernel customizations explains how Android balances performance and security on mobile.
Under the Hood
At runtime, Android apps are compiled into an intermediate format called bytecode. ART compiles this bytecode into native machine code ahead of time during app installation. The Linux kernel manages hardware access and system resources, enforcing security and multitasking. The framework provides APIs that translate app requests into system calls handled by ART and the kernel.
Why designed this way?
Android's layered design separates concerns: hardware management, app execution, and app development tools. This modularity allows Google to update parts independently, supports many hardware types, and provides a stable environment for apps. The use of ART ahead-of-time compilation was chosen to improve app performance and battery life over the older just-in-time compilation.
┌─────────────────────────────┐
│       Android Framework      │
│  (APIs, UI components, etc.)│
├─────────────┬───────────────┤
│             │               │
│         ART Runtime          │
│ (Ahead-of-Time compiled code)│
├─────────────┴───────────────┤
│        Linux Kernel          │
│ (Hardware drivers, security)│
└─────────────────────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Do apps run directly on the Linux kernel? Commit to yes or no.
Common Belief:Apps run directly on the Linux kernel for better performance.
Tap to reveal reality
Reality:Apps run on the Android Runtime (ART), which sits above the Linux kernel.
Why it matters:Thinking apps run on the kernel leads to misunderstanding app security and stability mechanisms.
Quick: Is ART a virtual machine like Java's JVM? Commit to yes or no.
Common Belief:ART is a virtual machine that interprets code at runtime like JVM.
Tap to reveal reality
Reality:ART compiles app code ahead of time into native code, not interpreting it at runtime.
Why it matters:Believing ART interprets code can cause confusion about app performance and battery usage.
Quick: Does the Android framework include hardware drivers? Commit to yes or no.
Common Belief:The Android framework includes hardware drivers for devices.
Tap to reveal reality
Reality:Hardware drivers are part of the Linux kernel layer, not the framework.
Why it matters:Mixing these layers can lead to incorrect assumptions about where to fix hardware issues.
Quick: Is the Linux kernel in Android the same as desktop Linux? Commit to yes or no.
Common Belief:Android uses the exact same Linux kernel as desktop Linux without changes.
Tap to reveal reality
Reality:Android uses a customized Linux kernel with mobile-specific features.
Why it matters:Ignoring kernel customizations can cause misunderstandings about Android's power and security features.
Expert Zone
1
The ART runtime uses profile-guided optimizations to recompile hot code paths for better performance after initial app use.
2
Android's kernel includes wakelocks, a mechanism to control power usage by preventing the device from sleeping during critical tasks.
3
The framework's Binder IPC mechanism is a lightweight way for apps and system services to communicate securely and efficiently.
When NOT to use
This architecture is specific to Android devices. For other platforms like iOS, different runtimes and kernels are used. Also, for very low-level hardware programming, direct kernel modules or native code outside ART might be necessary.
Production Patterns
In production, developers rely on the framework APIs to ensure compatibility across devices. System updates often include kernel and ART improvements to enhance security and performance without changing app code.
Connections
Operating System Design
Android architecture builds on core OS principles like kernel-user space separation.
Understanding general OS design helps grasp why Android separates hardware control from app execution.
Just-In-Time vs Ahead-Of-Time Compilation
ART uses ahead-of-time compilation, contrasting with JIT used in other runtimes.
Knowing compilation strategies clarifies trade-offs in app startup speed and battery life.
Restaurant Kitchen Workflow
Android layers coordinate like kitchen staff, chef, and recipe book working together.
Seeing software layers as roles in a kitchen helps understand their collaboration and separation of duties.
Common Pitfalls
#1Assuming apps can access hardware directly.
Wrong approach:val camera = Camera.open() camera.startPreview() // Direct hardware access without permissions or framework
Correct approach:val camera = CameraManager.openCamera() // Use framework APIs with proper permissions
Root cause:Misunderstanding that hardware access must go through Android framework and kernel for security.
#2Expecting app code to run instantly without compilation.
Wrong approach:Running raw bytecode without ART compilation step.
Correct approach:Relying on ART's ahead-of-time compilation during app install.
Root cause:Not knowing ART compiles code ahead of time to improve performance.
#3Confusing framework APIs with kernel functions.
Wrong approach:Trying to call Linux kernel functions directly from app code.
Correct approach:Using Android framework APIs that internally communicate with the kernel.
Root cause:Lack of understanding of Android's layered architecture and abstraction.
Key Takeaways
Android architecture is a layered system with the Linux kernel at the base, ART runtime in the middle, and the framework on top.
The Linux kernel manages hardware and system resources, providing a stable foundation for Android.
ART compiles app code ahead of time to improve app performance and battery life.
The Android framework offers developers tools and APIs to build apps without handling low-level hardware details.
This design ensures apps run securely, efficiently, and consistently across many devices.