Compile platform
The software platform
-Win10 Home 64bit -Vmware Workstation 15 -Ubuntu 14.04.6LTS – Openjdk1.8.0_45 -Android-8.1.0_r52
Hardware platform
-i7 8750H 32G 512G -Nexus 5x
Environment set up
1. Install Ubuntu on Vmware
Note: the virtual machine is recommended to allocate more than 200GB of space, the Android 8.1.0_R52 compiled about 152G, including the system occupied 156GB, but your hard disk should have at least 250GB of free space, because Vmware will also occupy part of the virtual machine folder after the author compiled about 214GB. In addition, you are advised to allocate more than 8 GB memory to the VM, and allocate cpus based on the CPU usage of the host.
2. Its installation
We compiled Android version 8.1, so we use OpenJDK8 here. The corresponding JDK of each Android version is as follows:
- Android 7.0 (Nougat) – Android 8.0 (Oreo) : Ubuntu – OpenJDK 8; Mac OS – JDK 8U45 or later
- Android 5.x (Lollipop) – Android 6.0 (Marshmallow) : Ubuntu – OpenJDK 7; Mac OS – jdk-7u71-macosx-x64.dmg
- Android 2.3.x (Gingerbread) – Android 4.4.x (KitKat) : Ubuntu – Java JDK 6; Mac OS – Java JDK 6
- Android 1.5 (Cupcake) – Android 2.2.x (Froyo) : Ubuntu – Java JDK 5
(1) Download. Deb package:
- openjdk-8-jre-headless_8u45-b14-1_amd64.deb
(SHA256:0 f5aba8db39088283b51e00054813063173a4d8809f70033976f83e214ab56c0)
- openjdk-8-jre_8u45-b14-1_amd64.deb
(9 ef76c4562d39432b69baf6c18f199707c5c56a5b4566847df908b7d74e15849 SHA256:)
- openjdk-8-jdk_8u45-b14-1_amd64.deb
(SHA256:6 e47215cf6205aa829e6a0a64985075bd29d1f428a4006a80c9db371c2fc3c4c)
(2) (Optional) Verify the checksum of the downloaded files against the SHA256 string listed with each of the above packages. For example, using the sha256sum tool:
Sha256sum {downloaded.deb file}Copy the code
(3) Install the downloaded three software packages in sequence:
Sudo DPKG -i {download.deb file}Copy the code
A message may be displayed indicating that dependencies are missing after the installation. You can run the following command to automatically install dependencies:
sudo apt-get -f install
Copy the code
3. Install the software package required for compilation
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
Copy the code
4. Configuration Git
git config --global user.name "Your name"
git config --global user.email "Your email"
Copy the code
5. Download the REPO tool
Because of the special situation in China, tsinghua’s mirror source is used here
mkdir ~/bin
PATH=~/bin:$PATH
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo
Copy the code
If you want to use tsinghua’s mirror source for updates, you can use the following command to temporarily set the address to Tsinghua’s source (you can copy it to your ~/.bashrc permanently).
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'
Copy the code
Download the source code
1. Create a working directory
First we’ll set up a working directory where the downloaded source code and compiled output will be stored
mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
Copy the code
2. Initialize the warehouse
Repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest - b android - 8.1.0 _r52Copy the code
3. Synchronize the source tree
repo sync -j4
Copy the code
Note: The parameter after -j should not be too large, otherwise 503 error will appear, at the same time, try to ensure that the network is not interrupted during this process
4. Clear cache files
Repo Sync supports breakpoint continuations, but not purely breakpoint continuations. Files that have been downloaded before will be skipped, but files that have not been downloaded before will be re-downloaded and then cleaned up
find . -iname tmp_pack_* | xargs rm
Copy the code
Download the proprietary driver
Since we will eventually burn to a physical device, we will need to download a proprietary driver, which can be ignored if running on an emulator
Take Nexus 5X as an example, we need to download the following drivers:
hardware | supplier | link |
---|---|---|
Vendor image | LG | download |
GPS, Audio, Camera, Gestures, Graphics, DRM, Video, Sensors | Qualcomm | download |
These packages contain self-extracting scripts, run the included self-extracting scripts from the root of the source tree, and then confirm that you agree to the terms of the included license agreement. The binaries and their corresponding Makefiles will be installed in the vendor/ directory of the source tree
Since we haven’t compiled anything before, we don’t need to perform specific cleanup operations. Otherwise, clean up compiled output before compiling:
make clobber
Copy the code
Begin to compile
1. Initialize the script
source build/envsetup.sh
Copy the code
In this step, the script initializes many of the tools necessary for compilation
2. Select a compilation target
lunch
Copy the code
This command will help us list the compilation targets supported by the current version
Note that the compilation targets output here are in the form of phone code names, such as Bullhead for the Nexus 5X
3. Select a compilation type
Compile type | usage |
---|---|
user | Limited authority; Suitable for production environment |
userdebug | Similar to “user”, but with root permission and debuggability; Is the preferred compilation type for debugging |
eng | Development configuration with additional debugging tools |
We need to debug the system later, so we select AOSP_bullhead-userdebug, enter 29 and press Enter to select, then the system will compile and configure for the selected compilation target
4. Compile
make -j16
Copy the code
Note: the -j parameter can be determined by the number of cpus allocated to the vm. For example, if we assign a VM with 1 CPU, 8 cores per CPU, and 2 threads per kernel, we can use a command between make-j16 and make-j32 to achieve the fastest compilation speed
Of course, this step is not always smooth, there are always various problems, the most common is memory overflow:
This is due to the Java heap overflow, the solution is:
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
./prebuilts/sdk/tools/jack-admin kill-server
./prebuilts/sdk/tools/jack-admin start-server
Copy the code
Then continue compiling
5. The compilation is successful
This compilation time depends on the hardware configuration, and the author’s computer finally completed the compilation in a little more than an hour
Brush into the equipment
Configure USB permission
If you are developing on Ubuntu Linux, you need to add a Udev rule file containing USB configuration for each device type you want to use in your development. In the rules file, each device manufacturer is assigned a unique supplier ID, some of which are shown below:
(1) Create rule file:
sudo gedit /etc/udev/rules.d/51-android.rules
Copy the code
(2) Add suppliers to the file using the following format:
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
Copy the code
Note: The Nexus 5X should be supplied by Google, not LG
(3) Set file permissions:
chmod a+r /etc/udev/rules.d/51-android.rules
Copy the code
Now unplug the device and plug it in. Adb verifies that it can identify:
adb devices
Copy the code
(4) After the device is successfully connected, now enter the Fastboot mode:
adb reboot bootloader
Copy the code
(5) After the device is in Fastboot mode, run the following command to brush the entire Android system:
fastboot flashall -w
Copy the code
Before running this command, you must unlock the device. The -w option will clear the /data partition on the device. This option is useful for first brushing of a particular device, but is not necessary in other cases.
After the brush is complete, the system will restart automatically