How to Compiling an Android ROM within a VMware virtual machine
Host Machine: A powerful computer with at least 16GB of RAM (32GB or more recommended), a fast multi-core processor, and substantial free storage (SSD is highly recommended for speed).
VMware Software: VMware Workstation Pro.
Operating System: A 64-bit Linux distribution for the guest VM, such as Lubuntu (typically the latest LTS version recommended by AOSP) or Debian [1].
Step-by-Step Guide
1. Set up the VMware Virtual Machine
Create a New VM: Use the VMware software to create a new virtual machine.
Allocate Resources: This is crucial. Allocate at least:
RAM: 11GB (32GB for a faster build).
Processor Cores: 4 or more virtual cores.
Storage: At least 250GB of disk space (SSD performance is highly recommended). Use a pre-allocated disk size for better performance.
Install Linux: Install your chosen Linux distribution (e.g., Ubuntu) inside the VM. Req: Lubuntu
2. Prepare the Build Environment
Once Linux is installed and running in the VM, open a terminal and follow these steps.
Update System: Ensure your system is up-to-date:
bash
sudo apt update && sudo apt upgrade
Install Dependencies: AOSP requires specific packages and dependencies. The exact list can vary slightly depending on the Android version you are compiling, but a general command for Ubuntu is:
bash: https://source.android.com/docs/setup/start/requirements
Note: The required OpenJDK version depends on the Android version you are building (e.g., Android 11+ uses OpenJDK 11, older versions used OpenJDK 8). Check the official AOSP requirements page for the exact version.
Configure USB (Optional): If you plan to flash the compiled ROM directly from the VM to a physical device, ensure VMware USB passthrough is set up and working correctly.
3. Sync the Android Source Code
Install repo: The AOSP uses the repo tool to manage its numerous Git repositories. Install it using the instructions on the AOSP source setup guide.
Initialize your Repository: Choose a directory and initialize the branch you want to build (e.g., the android-13.0.0_r1 tag):
bash
mkdir ~/.bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
chmod a+x ~/.bin/repo
export PATH=~/.bin:$PATH
mkdir android
cd android
repo init -u https://github.com/xxxx/platform_manifests -b android-7.1.1_r55
Sync the Code: Download the entire source tree. This will take a significant amount of time and bandwidth:
bash
repo sync --depth=1 -c --no-tags --no-clone-bundle -j9
repo sync -c --no-tags --no-clone-bundle -j8
(The -j8 specifies 8 parallel download threads; adjust based on your network speed and system resources.)
jack server
https://xdaforums.com/t/discussion-how-to-fix-jack-server-failing-to-build-with-error-try-jack-diagnose.3575179/
4. Compile the ROM
Set up the Environment: Navigate to the root of your source directory and run:
bash
source build/envsetup.sh
Choose a Target Device: Select the specific device you are building for using the lunch command. You will see a list of available targets (e.g., aosp_cf_x86_64_phone for a virtual Cuttlefish device, or a specific physical device name if you added a device tree):
bash
lunch aosp_cf_x86_64_phone
Start the Build: Finally, begin the compilation process using the m or make command:
bash
m -j8
(The -j8 specifies 8 parallel build threads; adjust this number based on your CPU core count for optimal performance.)
The build process can take several hours, depending on your VM's allocated resources. Upon completion, the resulting image files (e.g., system.img, boot.img, userdata.img) will be located in the out/target/product/[device_name] directory.
