FORUMS
Remove All Ads from XDA

[GUIDE] How to Setup Ubuntu 16.04 LTS Xenial Xerus for Compiling Android ROMs

282 posts
Thanks Meter: 1,854
 
Post Reply Email Thread
--- reprinted with permission from nathanpfry.com ---

--- If you would rather use a ready-to-go Virtual Machine based on these instructions, check out this post! ---

With a new version of Ubuntu comes an update to my guide for setting up a build environment to compile Android ROMs. The aim of this is to simplify the configuration process and teach a little bit about the command line.

Follow the directions step-by-step. All you have to do is copy and paste the code in order, it will be up and running in no time!

This guide applies to all variations of Ubuntu 16.04 LTS Xenial Xerus 64 bit. Do not use the 32 Bit version.

Also, PAY CLOSE ATTENTION when to use "sudo" and when to not. It can cause unexpected issues if you do something as root that you shouldn't.

Much thanks goes out to Google, ProTekk, Canonical, and everyone else that I read a random paragraph here and snippet there.

Ready to begin?


1) Unless it's a completely fresh Ubuntu installation, many people might have the wrong version of Java installed. Let's fix that first.

The command below makes sure you're starting with a clean slate. Copy and paste it into a terminal (command prompt) window:

Code:
sudo apt-get remove openjdk-* icedtea-* icedtea6-*
If necessary, follow the on-screen instructions to remove any stray Java versions. Otherwise, move on to the next step.

2) Install the main build tools with this command:

Code:
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
3) "repo" communicates with git servers for all that precious source code. The next command will grab it:

Code:
mkdir ~/bin && curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo && chmod a+x ~/bin/repo
4) Use your favorite text editor to open ~/.bashrc - I like nano:

Code:
nano ~/.bashrc
5) At the very bottom (use the Page Down key) paste this code to a new line:

Code:
export PATH=~/bin:$PATH
export USE_CCACHE=1
6) Save it. In nano that would be Ctrl-O and then Enter. Then Ctrl-X to exit back to a prompt. Restart bash:

Code:
source ~/.bashrc
7) In the terminal, navigate to where you would like to download the Android source code. The commands below will make it in your home folder, but if you have limited space you may want to create it somewhere else. Faster is better, i.e. SSD would be best, USB external (even 3.0) will be comparatively slow. Here we go:

Code:
mkdir ~/android
cd ~/android
8) Now you're going to initialize the repo. This is where you decide the flavor of Android you want to build, i.e. AOKP, CyanogenMod, AOSP etc.

For the purposes of this tutorial, here's the command for Cyanogenmod 13 (Marshmallow) :

Code:
repo init -u https://github.com/CyanogenMod/android.git -b cm-13.0
9) Time to get the source, many gigabytes of downloading await.

Don't worry, it's automated. It's the last one!

Code:
repo sync
Check back periodically every hour or so. It all depends on how fast your connection is.

10) Now, for Java. Some ROMs (Android Lollipop / CM 12.1 and below) require OpenJDK 7. Marshmallow / CM 13 and above require OpenJDK 8. If you're building for reallllllly old devices, OpenJDK 6. Here's the easiest way to install on Ubuntu 16.04.

First, add the PPA for OpenJDK:

Code:
sudo add-apt-repository ppa:openjdk-r/ppa
Then, install the appropriate version of Java. In this case we're going to use 7, because it's popular. Simply replace openjdk-7-jdk with 6 or 8 as needed.

Code:
sudo apt-get update && sudo apt-get install openjdk-7-jdk
That's it! Everything should be ready to go.

If this guide helped you out, feel free to click the Thanks! button or donate to the new hardware fund
The Following 65 Users Say Thank You to sylentprofet For This Useful Post: [ View ] Gift sylentprofet Ad-Free
 
 
22nd April 2016, 05:26 AM |#2  
Senior Member
Thanks Meter: 31
 
More
Observations
I just happened to have a literally minutes-old ISO download of this version of Kubuntu (release - replacing beta 2) ready to install when I saw this, therefore I followed it to the T.

It was, in fact, helped that I did the repo sync prior to washing my hands before dinner.

After eating, putting away leftovers, etc. (the usual post-dinner cleanup detail), I came back to find the repo sync had completed.

Next was installing openjdk8 - only to find that it had, in fact, been already grabbed when I grabbed the prereqs - then I remembered why. Between Wiley and Xenial, both JDK and OpenJDK had finished their respective transitions from 7 to 8. Still, better safe than sorry - after making sure that both the Java-related settings matched (the last two sudos), I ran repo sync one last time before writing this post.
All five hundred sixteen projects in the CM-13 tree.

What helped - having loads of bandwidth. (No - I'm not on a college connection; I have a DOCSIS 3.0 cable modem - specifically an ARRIS SurfBoard SB-6183 - and Comcast's second SLOWEST DOCSIS 3 tier (Performance Pro) - which is STILL a frigging crapton of bandwidth; I've generally hit ten megaBYTES per second of transfer when connecting via Team Akamai - no git connection is gonna tax that.
Unless there is a massive-to-monstrous surge in projects against CM-13's tree, not a single subsequent repo sync will be as massive as the first one - which itself was less than thirty minutes.
(Each repo sync after the first downloads/uploads only the CHANGES in the tree - it's the FIRST sync that's the time and bandwidth eater due to it pulling the entire tree.)
The Following 2 Users Say Thank You to PGHammer For This Useful Post: [ View ] Gift PGHammer Ad-Free
23rd April 2016, 09:42 PM |#3  
Senior Member
Thanks Meter: 135
 
More
Is there a way to install JDK-7 in 16.04 ? Some Roms needed JDK7
The Following User Says Thank You to NoN1979 For This Useful Post: [ View ] Gift NoN1979 Ad-Free
24th April 2016, 01:08 AM |#4  
OP Senior Member
Flag Sacramento
Thanks Meter: 1,854
 
Donate to Me
More
Quote:
Originally Posted by NoN1979

Is there a way to install JDK-7 in 16.04 ? Some Roms needed JDK7

OP updated with directions at the bottom. Thanks for the support!
The Following 4 Users Say Thank You to sylentprofet For This Useful Post: [ View ] Gift sylentprofet Ad-Free
28th April 2016, 12:46 AM |#6  
desalesouche's Avatar
Senior Member
Thanks Meter: 4,131
 
Donate to Me
More
Quote:
Originally Posted by sylentprofet

OP updated with directions at the bottom. Thanks for the support!

hi may i ask for some help here? compiling cm-12.1 on ubuntu 16.04. does my errors are related with 16.04 ? i had no problem with 15.10. thank you.
http://pastebin.com/1X0WcZAr
28th April 2016, 01:45 AM |#7  
I set my ubuntu 16.04 lts like your guide thread, But I build CM 12.1, It show me 'unsupported reloc 43 against global symbol stderr'

Code:
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld: error: ~/cm12/out/host/linux-x86/obj32/EXECUTABLES/third_party_libvpx_libvpx_obj_int_extract_arm_host_gyp_intermediates/third_party/libvpx/source/libvpx/build/make/obj_int_extract.o: unsupported reloc 43 against global symbol stderr
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld: error: ~/cm12/out/host/linux-x86/obj32/EXECUTABLES/third_party_libvpx_libvpx_obj_int_extract_arm_host_gyp_intermediates/third_party/libvpx/source/libvpx/build/make/obj_int_extract.o: unsupported reloc 43 against global symbol stderr
external/chromium_org/third_party/libvpx/source/libvpx/build/make/obj_int_extract.c:31: error: unsupported reloc 43
external/chromium_org/third_party/libvpx/source/libvpx/build/make/obj_int_extract.c:787: error: unsupported reloc 43
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How to fix it?
It show always what I build Android ROMs. :/
28th April 2016, 02:13 AM |#8  
desalesouche's Avatar
Senior Member
Thanks Meter: 4,131
 
Donate to Me
More
Quote:
Originally Posted by CNBLACK

I set my ubuntu 16.04 lts like your guide thread, But I build CM 12.1, It show me 'unsupported reloc 43 against global symbol stderr'

Code:
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld: error: ~/cm12/out/host/linux-x86/obj32/EXECUTABLES/third_party_libvpx_libvpx_obj_int_extract_arm_host_gyp_intermediates/third_party/libvpx/source/libvpx/build/make/obj_int_extract.o: unsupported reloc 43 against global symbol stderr
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/bin/ld: error: ~/cm12/out/host/linux-x86/obj32/EXECUTABLES/third_party_libvpx_libvpx_obj_int_extract_arm_host_gyp_intermediates/third_party/libvpx/source/libvpx/build/make/obj_int_extract.o: unsupported reloc 43 against global symbol stderr
external/chromium_org/third_party/libvpx/source/libvpx/build/make/obj_int_extract.c:31: error: unsupported reloc 43
external/chromium_org/third_party/libvpx/source/libvpx/build/make/obj_int_extract.c:787: error: unsupported reloc 43
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How to fix it?
It show always what I build Android ROMs. :/

Same problem here, see post above
28th April 2016, 02:20 AM |#9  
Quote:
Originally Posted by desalesouche

Same problem here, see post above

humm.. I found solution this issue, but It is temporarily solution.

Code:
ln -sf /usr/bin/ld.gold /home/(your account name)/(build source repository)/prebuilts/gcc/linux-x86/host/(glibc version)/x86_64-linux/bin/ld
check your glibc version in terminal error line.
And If you find it, You need to type this command. And It'll be work.
The Following 2 Users Say Thank You to OnyxClover For This Useful Post: [ View ] Gift OnyxClover Ad-Free
28th April 2016, 11:00 AM |#10  
And It has a one more problem.

Code:
mkdir -p /home/cnblack/build/sgs2/12.1/out/target/product/i9100/obj/PACKAGING/recovery_patch_intermediates/
PATH=/home/cnblack/build/sgs2/12.1/out/host/linux-x86/bin:$PATH /home/cnblack/build/sgs2/12.1/out/host/linux-x86/bin/imgdiff /home/cnblack/build/sgs2/12.1/out/target/product/i9100/boot.img /home/cnblack/build/sgs2/12.1/out/target/product/i9100/recovery.img /home/cnblack/build/sgs2/12.1/out/target/product/i9100/obj/PACKAGING/recovery_patch_intermediates/recovery_from_boot.p
Error: inflate failed [invalid block type] at file offset [2535779]
imgdiff only supports gzip kernel compression, did you try CONFIG_KERNEL_LZO?
failed to break apart target image
I don't know Why I have to fix this trouble :/
29th April 2016, 03:46 PM |#11  
Member
Thanks Meter: 37
 
More
BuilduntuVM
@sylentprofet: Thanks a lot for that guide.

Do you consider to release an Ubuntu 16.04 LTS based BuilduntuVM (http://forum.xda-developers.com/show....php?t=2585828) sometime?
The Following User Says Thank You to revuwa For This Useful Post: [ View ] Gift revuwa Ad-Free
Post Reply Subscribe to Thread

Tags
android, build environment, compile, how to, ubuntu

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes