2. Compile environment to build

2.1. Ready to compile

Compiling Android requires high machine configuration:

  • 64-bit CPU

  • 16GB physical memory + swap memory

  • 250GB of free disk space

The official recommendation is the Ubuntu 18.04 operating system.

The initialization of the compilation environment can refer to http://source.android.com/source/initializing.html

  • Ubuntu 16.04 and 18.04 package installation reference:

sudo apt-get update

sudo apt-get install git gnupg flex bison gperf libsdl1.2-dev \
libesd-java libwxgtk3.0-dev squashfs-tools build-essential zip curl \
libncurses5-dev zlib1g-dev pngcrush schedtool libxml2 libxml2-utils \
xsltproc lzop libc6-dev schedtool g++-multilib lib32z1-dev lib32ncurses5-dev \
lib32readline-dev gcc-multilib libswitch-perl libssl-dev unzip zip device-tree-compiler \
liblz4-tool python-pyelftools python3-pyelftools -y 

2.2. Compilation FAQ

Because everyone’s PC system version and environment configuration are different, the compilation after installing the software package is not necessarily successful, and it is inevitable that there will be some errors caused by the lack of some software packages, such as:

2.2.1. Q1

 OBJCOPY spl/u-boot-spl-nodtb.bin
  CAT     spl/u-boot-spl-dtb.bin
  COPY    spl/u-boot-spl.bin
  CFGCHK  u-boot.cfg
ERROR: No 'dtc', please: apt-get install device-tree-compiler

Don’t worry, we could install the lacking software package(dtc) according to the error message, just like you see:

apt-get install device-tree-compiler

2.2.2. Q2

Kernel have the compilation error(lz4 error):

  LZ4C    arch/arm64/boot/Image.lz4
Incorrect parameters
Usage :
      lz4 [arg] [input] [output]

input   : a filename
          with no FILE, or when FILE is - or stdin, read standard input
Arguments :
 -1     : Fast compression (default) 
 -9     : High compression 
 -d     : decompression (default for .lz4 extension)
 -z     : force compression
 -f     : overwrite output without prompting 
 -h/-H  : display help/long help and exit
arch/arm64/boot/Makefile:31: recipe for target 'arch/arm64/boot/Image.lz4' failed

You can compile lz4 in Android SDK and replace:

mmm external/lz4/ 
sudo cp /usr/bin/lz4 /usr/bin/lz4.org   # backup
sudo cp out/host/linux-x86/bin/lz4 /usr/bin/lz4 # replace

If this happens with compilation:

error: external/crosvm/rutabaga_gfx/Android.bp:91:1: "rutabaga_gfx_host_test_src_lib" depends on undefined module "libgfxstream_backend"
error: external/crosvm/rutabaga_gfx/Android.bp:13:1: "librutabaga_gfx" depends on undefined module "libgfxstream_backend"

That’s because you need to compile the ‘Android’ first. If you don’t want to compile, you can direct download the lz4 tool from the Link below to replace directly.

sudo cp /usr/bin/lz4 /usr/bin/lz4.org   # backup
sudo cp lz4 /usr/bin/lz4  # replace