[Android] Macbook Pro 10.14 (MacOS mobile) compiling Android 9.0 (aosp master) process record

Keywords: Android Mac xcode SDK

Remember the process of compiling Android source code

Experimental environment

  • MacOS Mojave 10.14; RAM 16G
  • SSD hard disk 960G
  • Access to google's Network Environment

Step 1: prepare the environment

Please refer to the official website: https://source.android.com/setup/build/initializing

  1. Prepare disk

    1. Disk image mode (25G is officially recommended, 60G + is recommended)
      # Create a. dmg (or. dmg.sparseimage) file
      hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size 60g ~/android.dmg
      
      # Resize
      hdiutil resize -size 100g ~/android.dmg.sparseimage
      
      # Add mount helper function in. Bash? Profile
      mountAndroid() { hdiutil attach ~/android.dmg.sparseimage -mountpoint /Volumes/android; }
      umountAndroid() { hdiutil detach /Volumes/android; }
      
    2. External hard disk mode: direct format external hard disk (MAC OS expansion (case sensitive, log based))
  2. Install Xcode command-line tools: this step generally requires the latest large version of Mac OS (currently requires MoJave)

    # When installing Xcode command-line tools, there will be some problems when using the latest version directly. You can download the old version of command-line tools at the following link (9.4.1)
    # Suggestions: https://developer.apple.com/download/more/
    xcode-select --install
    
  3. To install MacPorts: https://www.macports.org/install.php

    # After selecting the appropriate version to install from the above link, edit ~ /. Bash_profileto ensure that / opt/local/bin must appear before / usr/bin:
    export PATH=/opt/local/bin:$PATH
    
  4. Using MacPorts to prepare relevant compilation tools

    # gmake, libsdl, gnupg (gnupg2 is out of date), git
    POSIXLY_CORRECT=1 sudo port install gmake libsdl gnupg2 git
    
  5. Set the maximum number of filers

    # ~/.bash_profile:  set the number of open files to be 1024
    ulimit -S -n 1024
    
  6. Configure Repo and download source code

    mkdir ~/bin
    PATH=~/bin:$PATH
    # Download Repo
    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    chmod a+x ~/bin/repo
    
    # Mount the disk and create the source storage path
    mountAndroid
    mkdir /Volumes/android/aosp
    cd /Volumes/android/aosp
    
    # Check out branch default master plus - B android-8.1.0? R64 can be switched to 8.1
    repo init -u https://android.googlesource.com/platform/manifest
    
    # Up to one hour + download process
    repo sync
    
    # Switch branch to
    repo start android-8.1.0_r64 --all
    

Step 2: compile the source code

# Empty output directory
cd /Volumes/android/aosp
make clobber

# Generate compilation script
. build/envsetup.sh

# Select build objectives
lunch
aosp_x86_64-eng
# aosp:Android Open Source Project, which can be used for compilation;
# _X86_: binder supports 64 bit;
# -eng: have development version settings of various debugging tools, and have root and debug permissions

# make jN, generally N is 1-2 times of the current CPU core number. This process should take a little time:)
make -j4

Problem record

  1. Mac OS compiles Android source code and prompts that tools.jar cannot be found

    build/core/config.mk:663: error: Error: could not find jdk tools.jar at /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/../lib/tools.jar, please check if your JDK was installed correctly.
    
    

    Solution: it can ensure that the device has a JDK. Check the file and find that you need to configure the variable export Android Java home = $Java home in the. Bash profile. OK, you need to refresh it later: ~ /. Bash profile

  2. Unable to find the corresponding MAC os.sdk: internal error: Could not find a supported mac sdk: ["10.10" "10.11" "10.12" "10.13"]
    Solve:

    # First check the mac sdk version in XCode. My version is 10.14
    cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
    ls
    
    # Method 1: add it in the source directory Darwin supported SDK versions (I tried this method, but I still can't compile it in my device later)
    vim build/soong/cc/config/x86_darwin_host.go
    
    darwinSupportedSdkVersions = []string{
                    "10.10",
                    "10.11",
                    "10.12",
                    "10.13",
                    "10.14",
                }
    # Method 2. Download command ﹣ line ﹣ tools ﹣ Mac OS ﹣ 10.13 ﹣ for ﹣ Xcode ﹣ 9.4.1.dmg (previously 10.13) at https://github.com/phracker/mac osx-sdks/releases.
    

There are also references:
https://www.cnblogs.com/liumce/p/8027559.html
https://blog.csdn.net/yemao_guyue/article/details/80871390
https://www.jianshu.com/p/063a0bcdc7f5

Posted by saurabhdutta on Tue, 12 Nov 2019 08:48:13 -0800