Sync Unlegacy Android Source and compile Unlegacy Android by your own


  • Linux (64 bit, Do not use the 32 Bit version) installed on your PC, instructions are tested on the following distributions:
    • Ubuntu 16.04 LTS Xenial Xerus (Xubuntu, Lubuntu and Kubunto should be fine too).
    • Debian 8
  • At least 200GB free disk space
  • Good download speed, syncing Android source might take a while

Sync Source

  1. Install main build tools:
    sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 g++-multilib python-networkx libxml2-utils \
    bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng maven flex
    • Android 4.4, Android 5.1 and Android 6.0: add the PPA for OpenJDK and install OpenJDK 7
      sudo add-apt-repository ppa:openjdk-r/ppa
      sudo apt-get update && sudo apt-get install openjdk-7-jdk
    • Android 7.x only: Install OpenJDK 8
      sudo apt-get update && sudo apt-get install openjdk-8-jdk
  2. “repo” communicates with git servers for all that precious source code
    mkdir ~/bin && curl > ~/bin/repo && chmod a+x ~/bin/repo
  3. Open ~/.bashrc with a text editor (e.g. "nano")
    nano ~/.bashrc
    • At the very bottom (use the Page Down key) paste this code to a new line:
      export PATH=~/bin:$PATH
    • Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart the shell:
      source ~/.bashrc
  4. Create a folder to download the UA Android source code
    mkdir ~/android
    cd ~/android
  5. Now initialize the repo (replace *branch* with aosp-4.4, aosp-5.1, aosp-6.0 or aosp-7.1 depending on the UA Android version you like to compile)
    repo init -u git:// -b *branch*
  6. Sync the source (might take some hours, depends on your download speed)
    repo sync


  1. Once sync is done you can run
  2. . build/
  3. Lunch and make the otapackage
    lunch ua_device_codename && make otapackage
  4. Done! Enjoy your self compile Unlegacy-Android


  • Update the default Java version if needed
    sudo update-alternatives --config java
    sudo update-alternatives --config javc
  • Downgrading "make" might speed up compiling, you can check installed version by:
    make --version
    • download 3.82 from, extract it and cd into the path. Now run:
      sudo mv make ~/bin/
      ln -s $(which make) ~/bin/make
    • Check make version
      make --version

(Inspired by instructions from