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

时间:2023-03-09 22:48:05
[GUIDE] How to Setup Ubuntu 16.04 LTS Xenial Xerus for Compiling Android ROMs

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 openjdk-8-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

That's it on the package side of things.

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) Last step. 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.

That should be everything. Now you are ready to build Android. Good luck!

If this guide helped you out, feel free to click the Thanks! button

Some ROMs require OpenJDK 7. Here's the easiest way to install it on Ubuntu 16.04 since it's no longer in the main repositories.

First, add the PPA for OpenJDK:

Code:
sudo add-apt-repository ppa:openjdk-r/ppa

Then, install OpenJDK 7:

Code:
sudo apt-get update && sudo apt-get install openjdk-7-jdk

Finally, tell your system which version of Java and Java Compiler to use with the following commands. Enter each one separately and make the appropriate selection for OpenJDK 7:

Code:
sudo update-alternatives --config java
sudo update-alternatives --config javac

That's it! Everything should be ready to go.

http://forum.xda-developers.com/chef-central/android/guide-how-to-setup-ubuntu-16-04-lts-t3363669

https://source.android.com/source/initializing.html

http://blog.****.net/fuchaosz/article/details/51487585