Skip to main content

Guide to Compiling Android on Ubuntu 16.04 (Xenial Xerus) -- OpenJDK7 Installation on 16.04

Another Ubuntu release, another set of instructions to get Android source to compile.

This only applies to the x64 (64 Bit version). It will not compile on the i386 (32 Bit version).

Ubuntu has opted to dump OpenJDK7 in the Xenial Repositories. This just means we will need to add a custom PPA to install JDK7.

Why go with OpenJDK7 and not OpenJDK8?

Well, OpenJDK7 is required to build most popular AOSP 6.0.x ROM Sources as of right now, some examples include: DU, PN, Any Specific AOSP Tag, OmniROM, and Android-x86.

In order to build anything >=4.4.x you will need Oracle Java 6.

The only use case for OpenJDK8 would be those who only build CM (13+), PacROM (or any other CM derivative for that matter), or the 'master' branch of AOSP.

Follow these instructions exactly (don't just throw 'sudo' around either, it is only to be used in specific cases):

1) Remove all traces of Java:

  • sudo apt-get remove openjdk-* icedtea-* icedtea6-*

2) Add Xenial OpenJDK7 PPA & Fetch the new packages index:
  • sudo add-apt-repository ppa:openjdk-r/ppa && sudo apt-get update

3) Install all currently available updates to ensure no packages are broken:
  • sudo apt-get upgrade && sudo apt-get dist-upgrade

6) Install OpenJDK7 and all Android Build dependencies:
  • sudo apt-get install adb fastboot openjdk-7-jdk 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 python-mako python3-mako python python3 syslinux-utils google-android-build-tools-installer

# To install OpenJDK8, replace 'openjdk-7-jdk' ==> 'openjdk-8-jdk'
# To install Oracle Java 6, replace 'openjdk-7-jdk' ==> 'oracle-java6-installer'
# You can install all three Java versions, you will just need to select the default using the 'update-alternatives' command below

7) Remove all unnecessary packages:
  • sudo apt-get autoremove

8) Make a user accessible folder, and add it to path:
  • mkdir ~/bin && echo "export PATH=~/bin:$PATH" >> ~/.bashrc

9) Enable CCACHE to speed up builds:
  • echo "export USE_CCACHE=1" >> ~/.bashrc

10) Restart Bash
  • source ~/.bashrc

11) Configure Git (Replace with your Name & Email Address):

  • git config --global "John Doe"
  • git config --global

12) Download Repo, make it executable, and put it in our local $PATH folder:

  • curl > ~/bin/repo && chmod a+x ~/bin/repo

13) Make a folder for your ROM source of choice (in this case 'android'), and initialize the repo:
  • mkdir ~/android
  • cd ~/android
  • repo init -u UrlOfManifestofROM.git -b BranchName

14) Sync the Repo:
  • repo sync -j4 --force-sync

15) Setup your build enviroment:
  • . build/

16) Choose here:

# If you want to fetch device dependencies, and your ROM officially supports the target device -- goto step 16) a)

# If you want to build using local device tree, repo, and kernel directories -- goto step 16) b)

16) a) Breakfast
  • breakfast RomTag_DeviceCodeName-BuildType

# I'll use DirtyUnicorns on as an example

#'breakfast du_angler-userdebug' (Builds DU for Nexus 6P with userdebug, unless you know what you are doing, use userdebug)

# If you don't know your device codename, Google it, or just run 'breakfast', and look for it in the menu

16) b) Lunch
  • lunch RomTag_DeviceCodeName-BuildType

# I'll use DirtyUnicorns on as an example

#'lunch du_angler-userdebug' (Builds DU for Nexus 6P with userdebug, unless you know what you are doing, use userdebug)

# If you don't know your device codename, Google it, or just run 'lunch', and look for it in the menu

17) Build the ROM:
  • mka -j8 bacon

# mka is a refined make.

# -j8 is a variable number, if you have an Intel processor, take the number of cores and multiply by two, so, on my Quad-Core i5, 4x2=8. As noted by +Drew Walton, the 'mka' command auto analyses cpu availabillity, so the '-jx' arguement is not necessary unless you are building on a device where you want limited resources to be used (I have a server, where I am only allowed to use 4 cores to build, so 2 x 4 due to hyperthreading).

# bacon is most custom ROM's target for a flash-able .zip archive format, if you get an error like "No Target to Make: bacon", try 'make -j8 otapackage'.

18) Collect the ROM:
  • adb push ~/android/out/target/product/ /sdcard/

19) Flash ROM & Enjoy!

- Some ROMs don't sync in vendor repos by default. You'll need to do this by fetching your OEM's vendor from and cloning it into ~/PathToROMSource/vendor/OEMName. You can also do this via local manifest. Look at this one as an example. but I won't be explaining it here:

- Getting random Java or Host Binary (build output shows it building in the 'out/host' directory) related errors? Try a lower -j#, or, just exclude that part (it will default to -j1, which will take considerably longer).

- To change your default Java version, use these two commands (Make sure to use them both! Mix and matching Java versions will not go well!):

sudo update-alternatives --config java

# If building LP (Lollipop) - MM (Marshmallow): Select the option for 'java-7-openjdk-amd64'
# If building DN (Donut) - KK (KitKat): Select the option for 'java-6-oracle-amd64'
# If building CM (13+), Pac (Or any other CM derivative), or the 'master' branch of AOSP: Select the option for 'java-8-openjdk-amd64'

sudo update-alternatives --config javac

# If building LP (Lollipop) - MM (Marshmallow): Select the option for 'java-7-openjdk-amd64'
# If building DN (Donut) - KK (KitKat): Select the option for 'java-6-oracle-amd64'
# If building CM (13+), Pac (Or any other CM derivative), or the 'master' branch of AOSP: Select the option for 'java-8-openjdk-amd64'

NOTE: Some AOSP ROM Source trees have been updated to build with OpenJDK8, so, feel free to use it when you can, though, it isn't mandatory.

Getting Random HOST ART Library Errors?

A common error going around right now is the generic '' failure to build due to a linker error. This is due to a recent update in the BinUtils package in the Ubuntu and Debian repositories that AOSP hasn't accounted for yet (CM already merged the fix). To fix this, you need to cherry-pick two commits:
  • cd ~/PathToROMSource
  • cd art/build/
  •  git remote add cm
  • git fetch cm
  • git cherry-pick e5c6b049f3c716be60bc82d79c44c451f49b4ad5
  • git cherry-pick 0299788b7a974841aa3324a573fbf04f49a4f23c
  • # Thats it! Have fun building your ROM of choice from source!


  1. I think

    git remote add

    should read

    git remote add cm

    1. Replied to the wrong comment earlier on. Yes, it should have, I edited it. Thank you!

  2. Replies
    1. took a mental break from GS4 SCHi545 VRUGOF1 troubleshooting & Verizon's really getting paid for nothing actually ^_^ which is how I ended up here. I just kept clicking links and reading from your side bar. Your incredibly insightful ( & yes, very encouraging to know someone else will devote thought to solving a mystery--because it's there and being obviously ignored, which makes it all the more intriguing to discover WHY) post/tutorial/blog on unblocking Samsung's S4 security/bootloader issue. Plus, I like your writing style. This is all new to me but it's fascinating and I am getting tons of valuable info because of people like you-- knowledge sharing and relevancy of topics covered. Thank you.

    2. Thank you! I appreciate the nice comments you made. I use these blogs to keep my thoughts straight as well, so they benefit me too. Haha.

  3. Could you do a kernel turorial detailed as great this? TIA :D

  4. Thank you so much! I think @Rachael_Burns summed it up on the thanks so I'll just mash f6, lol. Thanks again my dude :D

  5. yes very good tutorial and all new developers stepping in to create rom from source for their device or roms they like tutorials like this are much appreciated. thank you and keep up good work. we all appreciate it.


Post a Comment

Popular posts from this blog

A rant about OEM lazieness as it pertains to Proprietary Files

Ever wondered why x device slowed down after an upgrade to the newest android version? Or why y doesn't work on a source built ROM? A BIG part of the issue is OEM's laziness. The bigger part however, is proprietary binaries. Quite often, proprietary binaries are not updated for feature inclusion, or improvements, and are only updated for the purpose of making the hardware WORK, not WORK WELL. They often go out of their way to actually update the HAL's/RIL's/Proprietary Blobs. A great example of this is the RIL. The RIL (Radio Interface Layer) is updated EXTREMELY infrequently. Android's RIL interface is versioned. The current AOSP revision of it is 11. Now, the ril-daemon (Android component that communicates with the RIL) allegedly supports any RIL revision 6=<. A great example of these components not being updated is in the Nexus S (crespo). It was upgrade to JellyBean, which natively includes RIL version 7. Instead of updating it to get all the perk

Breaking Samsung's Security

Problem: The Verizon Galaxy S4 is bootloader locked. Well, what exactly is a Locked Bootloader? A locked bootloader checks for a digital signature on certain images/partitions on the device. This prompted me to begin to research ways to work around this. The Verizon Galaxy S4 (hereon referred to as VZW S4) checks the integrity of signatures on all of the following partitions; -           Boot (boot.img) -           TrustZone (TZ.img) -           Aboot   (aboot.mbn) -           RPM (RPM.mbn) -           SBL1 (sbl1.mbn) -           SBl2 (sbl2.mbn) -           SBl3 (sbl3.mbn) -           The Partition Map (JFLTE_USA_VZW.pit) -           Recovery (recovery.img) -           Modem -           NON-HLOS   Partitions not checked: -           System (/system, only checked during OTA Update) -           Persdata (/Data) -           Cache (/cache) -           Hidden.img Basic Understanding of the boot sequence: PDF: https://drive.go