Android Performance

Setting Up the Android System Development Environment

Word count: 720Reading time: 4 min
2018/11/01
loading

Whether you are an Android App developer or a System developer, having a foundational understanding of the Android system is extremely beneficial. I recently set up a development environment at home and decided to share the process for anyone interested.

The general steps involved are as follows:

  1. Installing Ubuntu
  2. Configuring Ubuntu
  3. Installing Essential Software
  4. Configuring a VPN (Optional)
  5. Downloading AOSP Code
  6. Setting Up the Build Environment and Compiling Pixel Code
  7. Flashing the Device
  8. Modifying and Compiling Framework, Services, and Res

While not strictly required, having the following makes the process much smoother:

  1. A PC or Laptop
  2. A 512GB SSD
  3. A Pixel device

1. Installing Ubuntu

For Linux development, I recommend using Ubuntu as your primary OS rather than a virtual machine. Installing it directly on your hardware provides better performance. The current recommended LTS version is 18.04. The installation process is fairly straightforward:

  1. Download Ubuntu 18.04: ubuntu 18.04
  2. Create a bootable USB drive using the tool recommended by Ubuntu.
  3. Install Ubuntu using the USB drive.

Ubuntu Desktop


2. Configuring Ubuntu

  1. Install an input method (e.g., Sogou Pinyin).
  2. Install vim: sudo apt install vim
  3. Install adb
  4. Install fastboot

3. Installing Essential Software

  1. VS Code
  2. Android Studio
  3. Meld (for diffing)
  4. Wine
  5. WPS Office

4. Configuring a VPN (Optional)

  1. ShadowSocks

5. Downloading AOSP Code

If you cannot access Google servers directly, I recommend using the Tsinghua University mirror: https://mirror.tuna.tsinghua.edu.cn/help/AOSP/

Download repo

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

Create Working Directory

1
2
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY

Initialize the Repository

1
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest

Sync the Code

(Using -c --no-tags downloads less data, speeding up the process)

1
repo sync -c --no-tags

6. Setting Up the Build Environment and Compiling Pixel Code

Install JDK

1
2
sudo apt-get update
sudo apt-get install openjdk-8-jdk

Install Dependencies

1
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc unzip

Download Pixel Drivers

When compiling code for the Android Master branch (or specific versions), you need to download the drivers corresponding to your device. You can find them here:
https://developers.google.cn/android/blobs-preview

Extracting drivers image

The extracted files should look like this:
Extracted Google devices

Compile the Pixel System Image

Run the following at the root of your source directory:

1
source build/envsetup.sh

Next, use the lunch command to select your device model and build type (user, userdebug, eng):

1
lunch

lunch command

After making your selection, type the corresponding number and start the compilation with make. You can use the -j flag to specify the number of threads (e.g., -j8 for 8 threads). Adjust based on your CPU performance:

1
make -j8

make process

Successful Compilation

The out directory will contain the generated images.
out folder


7. Flashing the Device

From the root of your source directory, run the following command to flash the system onto your device:

fastboot device

1
fastboot flashall

fastboot flashall output


8. Modifying and Compiling Framework, Services, and Res

Run the following commands from the root of your source directory.

  • Java Code: Use Android Studio for opening and editing.
  • C/C++ Code: Use SourceInsight, Eclipse, or VS Code.

Compiling Framework

1
mmm frameworks/base

Compiling Services

1
mmm frameworks/base/services

Compiling Res

1
mmm frameworks/base/core/res

Root and Remount

root and remount

Push Changes

Once you have root and remount access, you can adb push the modified framework, services, or res files to the device. Restarting the shell or the device will apply the changes. Alternatively, use adb sync system. This synchronizes the system directory from your out folder to the device, which is extremely convenient.

Example:

1
adb root && adb remount && adb shell stop && adb sync system && adb shell start

About Me && Blog

Below are my personal details and links. I look forward to connecting and sharing knowledge with fellow developers!

  1. About Me: Includes my WeChat and WeChat group links.
  2. Blog Navigation: A guide to the content on this blog.
  3. Curated Android Performance Articles: A collection of must-read performance optimization articles. Self-nominations/recommendations are welcome!
  4. Android Performance Knowledge Planet: Join our community for more insights.

“If you want to go fast, go alone. If you want to go far, go together.”

WeChat QR Code

CATALOG
  1. 1. Recommended Hardware
  • 1. Installing Ubuntu
  • 2. Configuring Ubuntu
  • 3. Installing Essential Software
  • 4. Configuring a VPN (Optional)
  • 5. Downloading AOSP Code
    1. 1. Download repo
    2. 2. Create Working Directory
    3. 3. Initialize the Repository
    4. 4. Sync the Code
  • 6. Setting Up the Build Environment and Compiling Pixel Code
    1. 1. Install JDK
    2. 2. Install Dependencies
    3. 3. Download Pixel Drivers
    4. 4. Compile the Pixel System Image
    5. 5. Successful Compilation
  • 7. Flashing the Device
  • 8. Modifying and Compiling Framework, Services, and Res
    1. 1. Recommended IDEs
    2. 2. Compiling Framework
    3. 3. Compiling Services
    4. 4. Compiling Res
    5. 5. Root and Remount
    6. 6. Push Changes
  • About Me && Blog