Open Devices

For some of the Xperia™ devices, we provide Android™ Open Source Project (AOSP) device configurations on GitHub. This means that the software will be open for you as a developer to use and contribute to. This is a way for us to support the open Android community, and it is also a tool for us to facilitate and verify contributions to AOSP.

Build AOSP Android 14

1. Prepare your Java environment

To prevent errors generated by having the wrong version of Java installed on your computer, we will start by removing any conflicting Java version and adding the correct version. Java 11 is needed to build Android.

  1. On your computer: In a terminal window, enter the following command:

sudo apt-get purge openjdk-* icedtea-* icedtea6-*

  1. A guide will appear on the screen. Follow the instructions to remove Java.
  2. Once Java is removed, install the correct version of Java by entering the following commands in a terminal window:

sudo apt-get update
sudo apt-get install openjdk-11-jdk
java -version

You should now see something similar to the following in your terminal window:

openjdk version "11.0.20.1" 2023-08-24 
OpenJDK Runtime Environment (build 11.0.20.1+1-post-Ubuntu-0ubuntu120.04) 
OpenJDK 64-Bit Server VM (build 11.0.20.1+1-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

2. Install the necessary tools to make an Android build

To be able to build the images that you will later flash on your device, you need to install a set of software packages and libraries which give you the tools to compile source code into binary files that can run on your device.

  1. In a terminal window, enter the following commands, all at once:

sudo apt-get install bison g++-multilib git gperf libxml2-utils make zlib1g-dev:i386 zip liblz4-tool libncurses5 libssl-dev bc flex curl python-is-python3 zlib1g-dev libelf-dev dwarves

Now you have the tools you need to compile and build a flashable AOSP image. Follow the steps below to learn how to do this.

3. Download Repo tool and set PATH

In order to access and use the source code available on the Sonyxperiadev GitHub, you need to install the Repo tool that is provided by Google.

  1. In a terminal window, enter the following commands to download and install Repo, and set the right access rules for it:

mkdir ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

  1. Open the bashrc file included in the repo tool:

nano ~/.bashrc

  1. To set the right path for your local bin folder, paste the following code to a new line at the very bottom of the bashrc file, and then save the file using Ctrl+X:

export PATH=~/bin:$PATH

  1. Reload bash variables to include the new path:

source ~/.bashrc

Now you have all the tools you need and can move on to initializing the AOSP code and Xperia device configurations. Learn how to do this below!

4. Initialise the AOSP tree

The next step is to create a folder on your computer and download the Android source code to it. To do this, note the branch in the Build information and follow the steps below.

BUILD INFORMATION:

  • security revision: 2024-09-05
  • build: AP2A.240905.003
  • branch: android-14.0.0_r67

For more information, see Android Codenames, Tags, and Build Numbers.

  1. In a terminal window, enter the following commands:

mkdir ~/android
cd ~/android
repo init -u https://android.googlesource.com/platform/manifest -b <branch>

Note: The downloaded data is over 20 GB, and to avoid running out of space during build we recommend at least 400 GB free hard disk space. Depending on your Internet connection, it can take quite a long time to download the source code. When the download has finished you have the basic AOSP source code on your computer.

  1. Clone the local_manifests from GitHub using the following commands:

cd .repo
git clone https://github.com/sonyxperiadev/local_manifests
cd local_manifests
git checkout <branch>
cd ../..

Note: These repos include a precompiled kernel. If you want to change or improve the kernel, you can recompile a new kernel. The new kernel binary should be placed in the corresponding device repository along with new kernel modules for wireless hardware. For more information, see the page how to rebuild kernels for Xperia devices.

  1. To download the code into the device repos created above, run the command:

repo sync -c -j8

  1. Cherry-pick the upstream patches

./repo_update.sh

5. Build AOSP images that can be flashed

Now you are ready to build AOSP images that can be flashed to a device. To do this, you have to point out your specific device and then start building the images.

  1. Enter the following commands:

source build/envsetup.sh

  1. Identify your device and enter the corresponding command:
    • Xperia 1 II: lunch aosp_xqat52-ap2a-userdebug
    • Xperia 1 III: lunch aosp_xqbc52-ap2a-userdebug
    • Xperia 1 IV: lunch aosp_xqct54-ap2a-userdebug
    • Xperia 1 V: lunch aosp_xqdq54-ap2a-userdebug
    • Xperia 10 II lunch aosp_xqau52-ap2a-userdebug
    • Xperia 10 III lunch aosp_xqbt52-ap2a-userdebug
    • Xperia 10 IV lunch aosp_xqcc54-ap2a-userdebug
    • Xperia 10 V lunch aosp_xqdc54-ap2a-userdebug
    • Xperia 5 II lunch aosp_xqas52-ap2a-userdebug
    • Xperia 5 III lunch aosp_xqbq52-ap2a-userdebug
    • Xperia 5 VI lunch aosp_xqcq54-ap2a-userdebug
    • Xperia 5 V lunch aosp_xqde54-ap2a-userdebug
  2. To start the build, type:

make -j$(nproc)

This step will take a long time. It may take up to several hours, so go grab a coffee or play a game while you wait. When it’s done, AOSP images that can be flashed to a device will be ready.

6. Enter fastboot mode

Before you flash the images that you built in the previous step, make sure your device is unlocked through Sony’s unlock boot loader service and that the device is in Fastboot mode.

To set your device in Fastboot:

All devices
  • On your device: Connect the device to your computer in Fastboot mode, by pressing volume up while inserting the USB cable.

Note: When the device is in Fastboot mode, the LED on the device will be illuminated in blue.

Devices released on 2020 and later
  • On you PC: Enter the following command and wait for the device to reboot:

fastboot reboot fastboot

Note: When the device is in Fastboot mode, it will display a menu with "fastbootd" as title.

7. Flash vendor image to your device

  1. Download the vendor image corresponding your device from List of devices and resources.
  2. Unpack the vendor zip file to obtain the vendor image.

SW_binaries_for_Xperia_AOSP_<android_version>_<kernel_version>_<release version>_<platform>.zip

Note: Release version should be equivalent to the latest downloaded image version, and platform should match your device.

  1. On your device: Connect the device to your computer in Fastboot mode, by pressing volume up while inserting the USB cable. When the device is in Fastboot mode, the LED on the device will be illuminated in blue.
  2. On your computer: Flash the vendor image by entering the following commands in a terminal window:

fastboot flash oem SW_binaries_for_Xperia_AOSP_<android_version>_<kernel_version>_<release version>_<platform>.img

Note: Release version should be equivalent to the latest downloaded image version, and platform should match your device.

8. Flash AOSP image to your device

To flash AOSP image to your device:

For most devices
  1. On your computer: Flash the boot, recovery, system and userdata images by entering the following commands in a terminal window:

fastboot flash boot out/target/product/<device>/boot.img
fastboot flash vbmeta out/target/product/<device>/vbmeta.img
fastboot flash dtbo out/target/product/<device>/dtbo.img
fastboot flash recovery out/target/product/<device>/recovery.img
fastboot flash system out/target/product/<device>/system.img
fastboot flash vendor out/target/product/<device>/vendor.img
fastboot flash userdata out/target/product/<device>/userdata.img
fastboot flash product out/target/product/<device>/product.img
fastboot flash vbmeta_system out/target/product/<device>/vbmeta_system.img
fastboot flash system_ext out/target/product/<device>/system_ext.img
fastboot flash vendor_boot out/target/product/<device>/vendor_boot.img
fastboot flash vendor_dlkm_a out/target/product/<device>/vendor_dlkm.img

Note: It’s not necessary to re-flash the userdata every time you flash your device, but sometimes the new software is incompatible with previous content, which might result in a device that doesn’t boot. If you experience this, try to re-flash only the userdata again.

Note: Several images may be missing depending on device layout.​

  1. Now when you disconnect your device from the computer and start it, it will be running AOSP.
For 2020+ devices
  1. On your computer: Enter the following command in a terminal window:​

fastboot erase metadata​

  1. Now when you disconnect your device from the computer and start it, it will be running AOSP.
For 2021+ devices
  1. Before flashing the built images please type on your computer:

fastboot reboot fastboot​

  1. This command will cause the device to reboot to fastboot and a menu will appear on the screen.

We hope this tutorial will help you get started building your own version of Android for Xperia devices.

Feel free to contribute your work back to our repositories on our Sonyxperiadev GitHub account.

We will review and merge your code as soon as possible.