Environment to prepare

It’s pretty clear on the official website, but here’s a quick summary:

Create a case-sensitive disk image

The MAC system is case insensitive by default, so we need to create a case sensitive file system

hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 60g ~/android.dmgCopy the code

This will create a.dmg.sparseImage file that, when loaded, can be used as a driver disk with the format required for Android development.

According to the website, you need at least 25GB of space to complete the compilation, and trust me, you need at least 60GB. Of course, the space size can be changed later by using the following command

hdiutil resize -size <new-size-you-want>g ~/android.dmg.sparseimageCopy the code

For convenience, we can also add helper functions to the environment variable configuration files (~/.bash_profile–bash, ~/.zshrc– ZSH)

  • Load function

    # mount the android file image
    mountAndroid() { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android;Copy the code
  • Uninstall function

    # unmount the android file image
    umountAndroid() { hdiutil detach /Volumes/android; }Copy the code

Install the required software

  • JDK

    Different Android versions use different Versions of Java, see related requirements

    I’m compiling Android8.1.0 here, so I’m using java1.8

  • Xcode command line tool

    xcode-select --installCopy the code
  • MacPorts

    To download the installation from macports.org, make sure that /opt/local/bin is displayed before /usr/bin in the path. Otherwise, add the following to the environment variable configuration file (~/.bash_profile–bash, ~/.zshrc– ZSH) :

    export PATH=/opt/local/bin:$PATHCopy the code

    Obtain the Make, Git, GPG, and BISON software packages from MacPorts

    POSIXLY_CORRECT=1 sudo port install gmake libsdl git gnupg bisonCopy the code

Set the maximum number of file descriptors

In Mac OS, the default upper limit for the number of file descriptors that can be opened at the same time is too low and may be exceeded in a highly parallel compilation process. To increase this limit, add the following line to the environment variable configuration file (~/.bash_profile–bash, ~/.zshrc– ZSH) :

# set the number of open files to be 1024
ulimit -S -n 1024Copy the code

Download the source code

The Android source tree is located in a Git code base hosted by Google. To make Git easier to use in an Android environment, Google developed Repo.

Install the Repo

  1. Make sure there is a bin/ directory in the home directory and that it is included in the path:

    mkdir ~/bin
    PATH=~/bin:$PATHCopy the code
  2. Download the Repo tool and make sure it is executable

    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    chmod a+x ~/bin/repoCopy the code

Repo initialization

Go to the file system we created initially and create an empty directory

➜ ~ mountAndroid /dev/disk3 GUID_partition_scheme /dev/disk3s1 EFI /dev/disk3s2 Apple_HFS /Volumes/android ➜ ~ CD /Volumes/ Android ➜ ~ mkdir aosp ➜ ~ CD aospCopy the code

Specify that you want to checkout correspondingSource code markup and compiled version

Repo init -u https://android.googlesource.com/platform/manifest - b android - 8.1.0 _r50Copy the code

After successful initialization, the directory should contain a.repo directory.

download

This is when the long download process begins

repo syncCopy the code

The synchronization will take an hour or more to complete if it goes well,

Download the driver

Download the driver of the corresponding model from the official website, decompress the driver, and execute the sh file in sequence, as shown in the following example:

$ ./extract-huawei-angler.sh

The license for this software will now be displayed.
You must agree to this license before using this software.

Press Enter to view the licenselsCopy the code

The driver file is released to the vendor directory.

compile

Clean up the

make clobberCopy the code

Set up the environment

source build/envsetup.shCopy the code

Select the target

➜ ~ Lunch You're building on Darwin Lunch menu... pick a combo: 1. aosp_arm-eng 2. aosp_arm64-eng 3. aosp_mips-eng 4. aosp_mips64-eng 5. aosp_x86-eng 6. aosp_x86_64-eng 7. aosp_deb-userdebug 8. aosp_flo-userdebug 9. full_fugu-userdebug 10. aosp_fugu-userdebug 11. mini_emulator_arm64-userdebug 12. m_e_arm-userdebug 13. mini_emulator_mips-userdebug 14. mini_emulator_x86-userdebug 15.  mini_emulator_x86_64-userdebug 16. aosp_flounder-userdebug 17. aosp_angler-userdebug 18. aosp_bullhead-userdebug 19. aosp_hammerhead-userdebug 20. aosp_hammerhead_fp-userdebug 21. aosp_shamu-userdebug 22. aosp_bullhead-userdebug 23. aosp_angler-userdebugCopy the code

Because I’m going to build the nexus6p, select 23 here, and other devices can refer to select devices to build the system

Compile the code

make -j8Copy the code

-jn indicates the number of parallel compilation tasks, depending on the computer, usually 1 or 2 times the number of cpus

Compilation problem

The corresponding macos.sdk cannot be found

  • An error log

    [44/44] bootstrap out/soong/.minibootstrap/build.ninja.in [4/4] out/soong/.bootstrap/bin/minibp out/soong/.bootstrap/build.ninja [860/861] glob vendor///Android.bp [54/54] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja FAILED: out/soong/build.ninja out/soong/.bootstrap/bin/soong_build -t -b out/soong -d out/soong/build.ninja.d -o Out /soong/build.ninja Android.bp internal error: Could not find a supported MAC SDK: ["10.10" "10.11" "10.12"] Ninja: build stopped: subcommand failed. 17:53:06 soong failed with: exit status 1Copy the code
  • The solution

    Modify/build/soong/cc/config/x86_darwin_host go file, add 10.14 support, are as follows

    DarwinSupportedSdkVersions = string [] {" 10.10 ", "10.11", "10.12", "10.14", / / add MAC SDK 10.14}Copy the code

Bison error encountered

  • An error log

    FAILED: out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/po licy_parse.c out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/po licy_parse.h BISON_PKGDATADIR=external/bison/data prebuilts/misc/darwin-x86/bison/bison -d --defines=out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/chec kpolicy/policy_parse.h -o out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/darwin_x86_64/gen/yacc/external/selinux/checkpolicy/po licy_parse.c external/selinux/checkpolicy/policy_parse.y [ 0% 309/87784] //external/libcxx:libc++_static header-abi-dumper src/random.cpp [arm] ninja: build stopped: subcommand failed. 18:05:05 ninja failed with: exit status 1Copy the code
  • The solution

    CD/Volumes/AOSP/external/bison git cherry - pick c0c852bd6fe462b148475476d9124fd740eba160 mm # original bison bison replace file is generated by the new cp / Volumes/AOSP/out/host/Darwin - x86 / bin/bison/Volumes/AOSP/prebuilts/misc/Darwin - x86 / bison / # to recompile the make - j8Copy the code

flash

After a long wait and repeated toss, finally arrived at the last step – brush machine.

Fastboot procedure flashing unlock fastboot flashall -wCopy the code

Done

Refer to the link

Source.android.com/setup/build… www.jianshu.com/p/1c3d47b20…