avatarRishabh Gupta

Summary

The provided web content offers a comprehensive guide to understanding the Android Open Source Project (AOSP) architecture, the importance of this knowledge for developers and users, and detailed instructions for building and flashing AOSP onto a device.

Abstract

The article titled "Understanding the Android Framework — AOSP: A Journey from Kernel to Application Layer" delves into the intricate architecture of the Android Framework, emphasizing its significance in the seamless functioning of Android devices. It outlines the layers of the Android system, including the Linux kernel, Hardware Abstraction Layer, Native Libraries, Android Runtime, and Framework Layer, among others. The narrative underscores the importance of understanding the Android Framework for optimizing device performance, developing high-quality applications, and leveraging the full potential of the Android ecosystem. It also serves as an introduction to a series of blog posts aimed at making the learning process enjoyable and informative. Furthermore, the article provides a step-by-step tutorial on how to clone the AOSP repository, configure the build environment, compile the source code, and flash the built images onto a device, illustrating the process with examples and command-line instructions.

Opinions

  • The author believes that understanding the Android Framework is crucial for gaining insights into the operation of Android devices and apps.
  • It is suggested that knowledge of the Android Framework allows users and developers to take proactive steps in optimizing performance and battery life.
  • The article promotes the idea that building AOSP from source is both an educational and empowering experience, giving users control over their device's software.
  • The author endorses the use of AOSP as a customizable and modifiable platform, highlighting the flexibility it offers to developers and OEMs.
  • There is an opinion that flashing a device with AOSP, especially from a memory card, is a safe process that minimizes the risk of bricking the device.
  • The article advocates for ZAI.chat, an AI service, as a cost-effective alternative to ChatGPT Plus(GPT-4), suggesting it as a valuable tool for those interested in the topic.

Understanding the Android Framework — AOSP : A Journey from Kernel to Application Layer

Welcome to the fascinating world of Android Frameworks! If you’ve ever marveled at the seamless experience of your Android device, from tapping icons to navigating apps, you’re witnessing the magic of the Android Framework at work.

In this blog, we’ll take a delightful dive into the architecture of the Android Framework, exploring its layers from the kernel to the application, and the most important why you should know it.

Will be writing subsequent more blogs on the same, with more detailed approach of making Frameworks fun to learn.

Understanding Android Frameworks: Why Does It Matter?

Before we delve into the nitty-gritty of Android Frameworks, let’s address the burning question:

Why should you know about it?

Well, the Android Framework serves as the backbone of every Android device, making sure your device’s parts and programs work together smoothly. By understanding how it all works, you gain invaluable insights into how your favorite apps tick and how to harness the full potential of the Android ecosystem.

Understanding the Android Framework is also essential for anyone who wants to fully comprehend the inner workings of their Android device, develop high-quality apps, optimize device performance, and harness the full potential of the Android ecosystem. It serves as the bridge that connects users, developers, and the Android platform, empowering them to unlock new capabilities and possibilities.

At its core, the Android Framework is the foundation upon which every Android device operates. It provides the essential infrastructure that enables hardware and software components to communicate and interact seamlessly.

Users who understand how the Framework manages system resources, handles background tasks, and prioritizes processes can take proactive steps to improve their device’s performance and battery life.

So as per GOOGLE!!!

The Android Open System Platform (AOSP) is publicly available and modifiable Android source code. Anyone can download and modify AOSP for their device. AOSP provides a complete and fully functional implementation of the Android mobile platform.

AOSP

AOSP architecture

1. Kernel Layer:

At the heart of the Android operating system lies the Linux kernel, providing essential functionalities such as memory management, device drivers, and process management. It serves as the bridge between the hardware and the upper layers of the Android Framework.

2. Hardware Abstraction Layer (HAL):

Next up, we encounter the Hardware Abstraction Layer, which abstracts hardware-specific functionalities into a standardized interface accessible to the Android Framework. This layer ensures compatibility across diverse hardware configurations, enabling seamless integration of new devices into the Android ecosystem.

3. Native Libraries:

Beneath the surface, many native libraries powers the core functionalities of the Android system, from graphics rendering to multimedia processing. These libraries, written in languages like C and C++, provide the raw horsepower needed to drive the user experience forward.

4. Android Runtime (ART):

Enter the realm of the Android Runtime, where Java bytecode is transformed into machine code through the magic of Ahead-of-Time (AOT) compilation. ART ensures the efficient execution of Android applications, optimizing performance and resource utilization for a smoother user experience.

5. Framework Layer:

Here’s where the magic truly happens! The Framework Layer encompasses a rich collection of Java classes and APIs that enable developers to build captivating Android applications. From UI components to system services, the Framework Layer empowers developers to create immersive experiences that captivate users worldwide.

6. System API:

The System API represents Android APIs available only to partners and OEMs for inclusion in bundled applications. These APIs are marked as @SystemApi in the source code.

7. System Service:

System services are modular, focused components such as system_server, SurfaceFlinger, and MediaService. Functionality exposed by Android framework API communicates with system services to access the underlying hardware.

The lower layer in detail

Dont worry!! I have not covered all the topics from the above layer. Will be explaining in details all the above modules and layers in the following articles.

In this one we will try to configure and build our AOSP code.

Building Your Own Android Adventure: AOSP and Beyond

Now that we’ve explored the architecture of the Android Framework, let’s embark on a thrilling journey of discovery: building and flashing Android code onto a rooted device!

First, ensure you have all the required tools installed:

  • Git: Version control system for managing source code.
  • JDK (Java Development Kit): Required for compiling Java code.
  • Android SDK: Provides tools and libraries for building Android apps.

Clone the AOSP Repository

Install “repo” Tool

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

Download the AOSP Source Code

mkdir ~/aosp
cd ~/aosp
repo init -u https://android.googlesource.com/platform/manifest

Sync Repo:

This step takes time as per the device and connectivity.

repo sync -j8

Building the source tree

Set Environment variable:

source build/envsetup.sh

Choose the Build Target

lunch
aosp_<device>-userdebug

Replace <device> with the codename of your device. “lunch” command will show the list of available build configurations. Choose the desired configuration for your device.

Initialize the build:

make -j8

With these commands, you can configure and build the Android Open Source Project (AOSP) code. Remember to choose the appropriate build target based on your device configuration before starting the build process.

Flashing the AOSP

Certainly the most convenient way of flashing a device is to remove its memory card and insert it into a card reader/writer attached to the build machine. On the build machine, all the standard partitioning and file system maintenance tools are available. In addition, a device that boots from removable memory is nearly impossible to brick: a huge advantage.

Many devices, even those that do not normally do so, are completely capable of booting from a memory card. Making this possible typically requires installing a custom bootloader.

The more common way of flashing images to a device, though, is by using fastboot. Again, the process of getting a device to fastboot mode is hardware dependent. On some devices, holding some combination of buttons immediately after powering on the device will cause it to enter fastboot mode.

Nearly any device, if running, can be forced to reboot into fastboot mode with the command “adb reboot bootloader

>> cd ../../../../..
> pwd
/home/acme/workspace
> fastboot flash boot out/target/product/hikey960/boot.img
target reported max download size of 471859200 bytes
sending 'boot' (9650 KB)...
OKAY [  0.345s]
writing 'boot'...
OKAY [  0.124s]
finished. total time: 0.468s
> fastboot flash dts out/target/product/hikey960/dt.img
target reported max download size of 471859200 bytes
sending 'dts' (14 KB)...
OKAY [  0.047s]
writing 'dts'...
OKAY [  0.048s]
finished. total time: 0.095s
> fastboot flash system out/target/product/hikey960/system.img
target reported max download size of 471859200 bytes
sending sparse 'system' 1/3 (445539 KB)...
OKAY [203.250s]
writing 'system' 1/3...
OKAY [ 10.197s]
sending sparse 'system' 2/3 (447504 KB)...
OKAY [198.764s]
writing 'system' 2/3...
OKAY [  8.254s]
sending sparse 'system' 3/3 (109822 KB)...
OKAY [ 46.770s]
writing 'system' 3/3...
OKAY [  1.566s]
finished. total time: 468.801s
> fastboot flash cache out/target/product/hikey960/cache.img
target reported max download size of 471859200 bytes
sending 'cache' (4280 KB)...
OKAY [  0.189s]
“writing 'cache'...
OKAY [  0.154s]
finished. total time: 0.343s
> fastboot flash userdata out/target/product/hikey960/userdata.img
target reported max download size of 471859200 bytes
sending 'userdata' (147713 KB)...
OKAY [  4.627s]
writing 'userdata'...
OKAY [  5.587s]
finished. total time: 10.214s

After executing the above commands, your device will be ready to boot with the freshly built images.

So, sit back and get ready to witness your Android device come to life with the latest AOSP code!

Happy building! 🚀🔧

Recommended from ReadMedium