When it comes to Android source code, many people imagine a monolithic archive with millions of lines of programming. In reality, it is a complex ecosystem of hundreds of repositories managed through a version control system. Android, as an open source operating system (except for proprietary components), provides developers with unique opportunities to study, modify and create their own firmware.

But where exactly is this code stored? How to obtain it, assemble it and adapt it to a specific device? In this article we will analyze Android Open Source Project (AOSP) the official project with sources, find out what tools are needed to work with the code, and consider practical scenarios for its use. Let us note right away: we will not be talking about โ€œhackingโ€ or bypassing restrictions, but about legal methods of working with the open part of the platform.

Android Open Source Project (AOSP) is a Google initiative under which most of the source code of the operating system is published. This is where developers can find the Linux kernel, libraries, frameworks, and core applications that form the foundation of Android. However, it is important to understand that AOSP โ‰  full Android on your smartphone.

Device manufacturers (Samsung, Xiaomi, OnePlus, etc.) add to AOSP their proprietary drivers, proprietary shells (for example, One UI or MIUI) and closed components (for example, modules for working with a camera or modem). Therefore, even if you build AOSP out of the box, it will not be fully functional on most commercial devices without additional modifications.

  • ๐Ÿ“‚ Linux kernel: a modified version of Linux, adapted for mobile devices.
  • ๐Ÿงฉ Libraries and runtime: including ART (Android Runtime) and Bionic (standard C library).
  • ๐Ÿ“ฑ Application framework: APIs that developers use to create applications.
  • ๐ŸŽจ Basic applications: Calendar, Contacts, Phone, etc. (without Google Apps).

AOSP is updated with each new version of Android. For example, the source code Android 14 became available in repositories immediately after the official release. However, some components (for example, Google services) remain closed and are not included in the public code.

๐Ÿ“Š Have you ever tried to build AOSP?
Yes, for your device
Yes, for an emulator
No, but I want to try
No, it's too complicated

Where the Android source code is stored: repository structure

Android code is not stored in one place - it is distributed over hundreds Git repositories, managed through a tool repo (a wrapper over Git from Google). All repositories are hosted on servers android.googlesource.com, but downloading them one by one is ineffective. Instead, a system of manifests is used, which describes which repositories and in which versions are needed to build a specific version of Android.

Main categories of repositories:

Category Examples repositories Purpose
Kernel kernel/common, kernel/msm-4.19 Linux kernel source code with patches for Android
System libraries bionic, libcore Implementation of standard C/C++ and Java libraries
Framework frameworks/base, frameworks/native API for application development and system services
Applications packages/apps/Settings, packages/apps/Contacts Sources of standard applications
Build tools build, prebuilts Scripts for building firmware (make, soong)

To get a complete list of repositories for a specific version of Android, use the manifest file (default.xml in the repository platform/manifest). For example, for Android 13 the manifest will contain links to all necessary components indicating their revisions.

โš ๏ธ Attention: Some repositories (especially those related to drivers for specific hardware) may be closed by manufacturers. This means that in order to fully build the firmware for Samsung Galaxy S23 or Xiaomi Redmi Note 12 additional proprietary binaries (blobs), which are usually extracted from official firmware, will be required. data-i="86">Attention:

How to download Android source code: step-by-step guide

The process of downloading Android source code requires preparation: you will need a Linux system (recommended Ubuntu 20.04/22.04with at least 100 GB of free space on disk and a stable Internet connection. Here are the main ones. steps:

  1. Install the necessary packages:
    sudo apt update
    

    sudo apt install -y git-core gnupg flex bison build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig

  2. Install repo:
    mkdir ~/bin
    

    PATH=~/bin:$PATH

    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

    chmod a+x ~/bin/repo

  3. Initialize the repository:
    mkdir WORKING_DIRECTORY
    

    cd WORKING_DIRECTORY

    repo init -u https://android.googlesource.com/platform/manifest -b android-14.0.0_r1

    Here android-14.0.0_r1 โ€” branch for Android 14. For other versions, use the appropriate tags (for example, android-13.0.0_r3).

  4. Synchronize the code:
    repo sync -j$(nproc)

    This process may take several hours depending on the Internet speed.

After synchronization is complete, a folder structure corresponding to the AOSP repositories will appear in the working directory. For example, the path to application sources Settings will be like this: packages/apps/Settings.

Install Ubuntu 22.04 LTS

Allocate 150+ GB on disk

Set up a swap file (16 GB recommended)

Install Java 11 (OpenJDK)

Download proprietary drivers for your device (if needed)

-->

How to build Android from source code: basic commands

Building Android from source - a resource-intensive process that can take from 1 to 4 hours depending on the PC configuration. Minimum requirements:

  • ๐Ÿ–ฅ๏ธ Processor: 4-core (8+ cores recommended).
  • ๐Ÿง  RAM: 16 GB (32 GB for acceleration).
  • ๐Ÿ’พ Disk space: 200+ GB (SSD required).

Basic commands for assembly:

  1. Environment initialization:
    source build/envsetup.sh

    After this, commands like lunch and m.

  2. Selecting a build target become available:
    lunch aosp_arm64-eng

    Here aosp_arm64-eng is a target for the 64-bit ARM architecture in engineering mode (with debugging capabilities used for specific devices). other purposes, for example aosp_cf_x86_64_phone-userdebug for the emulator.

  3. Start the build:
    m -j$(nproc)

    Flag -j indicates the number of parallel tasks (optimally - by the number of processor cores).

The build result will appear in directory out/target/product/{target}/. For the emulator this will be a file system.img, for real devices - a set of images (boot.img, recovery.img etc.), which can be flashed through fastboot.

โš ๏ธ Attention: Assembly for a real device requires proprietary binaries (vendor blobs), which are usually extracted from the official firmware using tools like extract-files.sh (present in the repositories of some custom firmware, for example, LineageOS).
๐Ÿ’ก

If the build is interrupted with an error "out of memory", reduce the number of parallel tasks (m -j4) or add a swap file.

Modifying the source code: what can be changed in Android

Having access to the source code, you can make changes at different levels of the system: Here are the most popular areas of modifications:

  • ๐Ÿ”ง Kernel: Optimization of the task scheduler, adding support for new hardware, patches to improve performance.
  • ๐ŸŽจ Interface: Changing the theme, animations, adding new elements to SystemUI (notification panel, navigation bar).
  • ๐Ÿ”’ Security: Removing unnecessary permissions, adding new control mechanisms (for example, SELinux policy).
  • ๐Ÿ“ฑ Applications: Modifying standard applications (for example, adding new functions to Camera or Phone).

An example of a simple modification: changing the text in the status bar To do this, you need to edit the file frameworks/base/packages/SystemUI/res/values/strings.xml, find the line. with the identifier status_bar_notification_info_overflow and change its value. After the reassembly, the text in the notification panel will be updated.

A more complex example - adding a new gesture. This will require:

  1. Change the code in frameworks/base/services/core/java/com/android/server/policy (gesture processing).
  2. Add new resources (icons, lines) to the appropriate folders.
  3. Update the configuration in frameworks/base/core/res/res/values/config.xml.

Important: any changes in system components may lead to unstable operation or incompatibility with applications. Always test modifications on an emulator before flashing the firmware to a real device.

What happens if you remove critical_app from Android?

Some system applications are marked as critical in the manifest. Removing them can lead to a bootloop (boot loop) or complete system inoperability. For example, deletion com.android.phone will deprive the device of the ability to work with a cellular network.

Proprietary components: what remains closed in Android

Despite the openness of AOSP, full-fledged firmware for commercial devices requires proprietary components. These proprietary binaries (blobs) include:

  • ๐Ÿ“ก Modem drivers (Qualcomm, MediaTek, Exynos).
  • ๐Ÿ“ท Image processing libraries (for example, for Sony IMX cameras).
  • ๐Ÿ”Š Audio codecs (Dolby, Hi-Fi DSP).
  • ๐Ÿ”‹ Power management (hardware-specific algorithms).

These components are usually supplied by manufacturers in the form of pre-compiled binaries (.so, .ko files) that are integrated into the firmware at the assembly stage. For example, for Google Pixel proprietary binaries can be found in repositories device/google, and for Samsung they are often extracted from official firmware using tools like Samsung Firmware Extractor.

Without these components, some functions may not work:

Component What breaks without it Where to get it
Modem driver No cellular connection (2G/3G/4G/5G) Official firmware of the manufacturer
Graphics driver Artifacts on the screen, low FPS Chipset manufacturer repositories
HAL camera The camera does not start or works with errors Firmware for a specific model
Wi-Fi/Bluetooth firmware No wireless connection Folder /vendor/firmware in the firmware

Projects like LineageOS or GrapheneOS solve this problem by providing instructions for extracting proprietary binaries from official firmware. However, the legality of this approach remains controversial, since the distribution of closed binaries may violate licensing agreements.

Practical application of Android source code

Knowledge of the structure and ability to work with Android source code opens up several practical scenarios:

  • ๐Ÿ› ๏ธ Creation of custom firmware: Developed based on AOSP LineageOS, Paranoid Android and other firmware with advanced functions.
  • ๐Ÿ” Security research: Analysis of code for vulnerabilities (for example, within the framework of bug bounty apps).
  • ๐Ÿ“ฑ Android port to a new device: Adaptation of the system for unofficially supported devices (for example, tablets or TV boxes).
  • ๐Ÿค– Development of emulators: Creation of custom assemblies for Android Emulator or Genymotion.

Example: if you want to port Android 14 to an old smartphone (for example, Xiaomi Mi A1), you will need to:

  1. Download the AOSP source code for the desired version.
  2. Add device configuration to device/xiaomi/ (or copy from existing repositories).
  3. Extract proprietary binaries from the official firmware.
  4. Build and flash the firmware via fastboot.

To simplify the process, there are tools like breakfast and brunch (from the set LineageOS), which automate some of the routine operations.

๐Ÿ’ก

Even if you do not plan to build firmware, studying the Android source code helps you better understand how the system works. This is useful for debugging applications, optimizing performance, and solving compatibility issues.

FAQ: Frequently asked questions about Android source code

Can Android source code be legally used in commercial projects?

Yes, but with reservations. Most of AOSP is distributed under a license Apache 2.0which allows the code to be used in commercial products provided that conditions are met (preserving copyright notices). However, some components (for example, the Linux kernel) are licensed under GPLv2, which obliges the publication of the source code of modified versions. In addition, the use of the "Android" trademark and Google services requires a separate agreement with Google.

Why is the source code of my smartphone different from AOSP?

Manufacturers make thousands of changes to AOSP: adding their drivers, modifying the framework to support proprietary functions (for example, DeX Mode in Samsung or HyperOS in Xiaomi), integrate proprietary libraries. In addition, they often use older versions of AOSP as a base, adding their own patches on top of them. For example, firmware based on Android 12 may contain elements from Android 11 and earlier versions.

Is it possible to build Android without proprietary binaries?

Technically yes, but such a system will be extremely limited. For example, the AOSP build for the emulator (aosp_x86_64-eng) does not require proprietary components and is fully functional in a virtual environment. However, for real devices without vendor blobs the camera, mobile communications, Wi-Fi, graphics acceleration and other critical functions will not work. Projects like Replicant try to replace proprietary components with open analogues, but their support is limited to a few devices.

How can I find out which version of AOSP is used in my smartphone?

There are several ways:

  1. View the build number in Settings โ†’ About phone โ†’ Build number. For example, RP1A.201005.004 corresponds Android 11.
  2. Use the command adb shell getprop ro.build.version.incremental to get the exact build number.
  3. Check the device manifest in manufacturer's repositories (for example, LineageOS often contains information about the base AOSP for supported models).
Where can you learn how to work with Android source code?

Recommended resources:

  • ๐Ÿ“– Official documentation: source.android.com (sections Getting Started and Porting).
  • ๐ŸŽ“ Courses: Udemy ("Android Internals") or Coursera ("Embedded Systems").
  • ๐Ÿ’ฌ Communities: XDA Developers, Reddit/r/AndroidDev, Telegram chats for custom firmware.
  • ๐Ÿ“บ YouTube: channels BigAndroidBBQ or Android Builders Summit with recordings of reports.

For practice, you can start with assembly AOSP for the emulator, then move on to porting to a real device with good documentation (for example, Google Pixel or OnePlus).