Skip to content

Instantly share code, notes, and snippets.

@felipendc
Last active September 24, 2020 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipendc/91b8b2b799e9a91d4ed1e25d7e2c2adf to your computer and use it in GitHub Desktop.
Save felipendc/91b8b2b799e9a91d4ed1e25d7e2c2adf to your computer and use it in GitHub Desktop.
BUILDING ANDROID FROM SOURCE
https://raw.githubusercontent.com/nathanchance/Android-Tools/master/Guides/Building_AOSP.txt
https://source.android.com/setup/build/initializing
to install all the packages needed!
####################################
# #
# BUILDING ANDROID FROM SOURCE #
# #
####################################
In this guide, I will go over how to build Android on your Linux machine.
This particular tutorial will focus on Ubuntu flavors but this should work with
any version of Linux; I include a reference for Arch users that is already done.
Your version MUST be 64-bit however. I will leave the installation of that up
to you, Google is a wonderful resource. If you don't have a good computer but
still want to build, check out this thread on XDA:
http://forum.xda-developers.com/chef-central/android/guide-how-to-build-rom-google-cloud-t3360430
Formatting!!!
If something has a $ in front of it, that is a command you need to run in your
terminal window. Don't include the $ or the space that follows it.
#######################################
# Step One: set up your environment #
#######################################
You have two options here, the lazy way or the non-lazy way.
Automatic way (recommended!):
-- Grab a repo with some useful scripts, and run the needed one
$ sudo apt-get install git-core
$ git clone https://github.com/akhilnarang/scripts
$ cd scripts
$ ls
$ bash setup/<script-name>
Run the script corresponding to your Linux Distribution:
arch-manjaro-apricity-build-environment-setup.sh - Arch based distros
ubuntu1604linuxmint18.sh - Ubuntu 16.04 or higher based distros
ubuntu1404.sh - Ubuntu 14.04
linuxmint17x.sh - Linux Mint 17.x
Manual way:
-- Grab Java 8:
$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk
$ sudo apt-get install openjdk-8-jre
-- Install build tools
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl \
zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev \
x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils \
xsltproc unzip
NOTE: Arch Linux users, use the Arch wiki page to install your packages then
come back here: https://wiki.archlinux.org/index.php/Android#Building_Android
######################################
# Step Two: Configure Repo and Git #
######################################
NOTE: If you have any problems with the below commands, try running as root:
$ sudo -s
Git is an open source version control system which is incredibly robust for
tracking changes across repositories. Repo is Google's tool for working with Git
in the context of Android. More reading if you are interested:
https://source.android.com/source/developing.html
Run these commands to get repo all working (only needed if you did the manual
method of setup above):
$ curl https://storage.googleapis.com/git-repo-downloads/repo > repo
$ chmod a+x repo
$ sudo install repo /usr/local/bin
$ rm repo
Then run these commands to get git all working:
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
#####################################
# Step Three: Download the source #
#####################################
First, create a folder for your source:
$ mkdir ~/<foldername> (eg. mkdir ~/DU or ~/PN-Layers)
$ cd ~/<foldername>
When you go to build a ROM, you must download its source. All, if not most,
ROMs will have their source code available on Github. To properly download the
source, follow these steps:
-- Go to your ROM's Github (e.g. http://github.com/DirtyUnicorns)
-- Search for a manifest (usually called manifest or android_manifest).
-- Go into the repo and make sure you are in the right branch (located right
under the Commits tab).
-- Go into the README and search for a repo init command. If one exists, copy
and paste it into the terminal and hit enter.
-- If one does not exist, you can make one with this formula:
repo init -u <url_of_manifest_repo>.git -b <branch_you_want_to_build>.
For example:
$ repo init -u http://github.com/DirtyUnicorns/android_manifest.git -b n7x
-- After the repo has been initialized, run this command to download the source:
$ repo sync --force-sync -j$( nproc --all )
-- This process can take a while depending on your internet connection.
##########################
# Step Four: Build it! #
##########################
Here's the moment of truth... time to build the ROM! This process could take
15 minutes to many hours depending on the speed of your PC but assuming that
you have followed the instructions so far, it should be smooth sailing.
Before you compile, you may also consider setting up ccache if you can spare
about 50GB. If not, skip this section. ccache is a compiler cache, which keeps
previously compiled code stored so it can be easily reused. This speeds up
build times DRASTICALLY.
Open your bashrc or equivalent:
$ nano ~/.bashrc
- Append export USE_CCACHE=1 to the end of this file
then hit ctrl-X, Y, and enter.
$ source ~/.bashrc
After that, run this command if you used the manual method of setup above
$ prebuilts/misc/linux-x86/ccache/ccache -M 50G (or however much you want).
Run this command if you used the automatic method of setup above
$ ccache -M 50G
After this, load up the compilation commands:
$ . build/envsetup.sh
Then, tell it which device you want to make and let it roll:
$ breakfast <device> OR lunch
$ mka bacon
NOTE: Some ROMs may use their own bacon command, read their manifest as they
will usually outline this.
Others may not use mka, use make -j$( nproc --all )
If you get an error here, make sure that you have downloaded all of the
proper vendor files from your ROM's repository.
Once you tell it mka bacon, the computer will start building. You
will know that it is done when you see a message saying make completed and
telling you where your flashable zip is located.
Whenever you build again, make sure you run a clean build every time by placing
this command in between the other two:
$ make clobber
That's it! You successfully compiled a ROM from scratch :) By doing this, you
control when you get the new features, which means as soon as they are available
on Github. After this, you may even want to start contributing, one of the
greatest things about Android and open source software in general.
#################
# Jack issues #
#################
For those of you who are having jack issues (like saying you ran out of memory),
follow these steps.
Type this into your terminal, substituting the # with how many GBs of RAM
you have:
$ export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx#g"
Then go into the root of the source folder and type the following:
$ ./prebuilts/sdk/tools/jack-admin kill-server
$ ./prebuilts/sdk/tools/jack-admin start-server
This will restart the jack server to reflect your new heap limit.
#############
# Support #
#############
If you have any questions, you can reach out to me via one of the following:
- Hangouts (natechancellor@gmail.com)
- Telegram (@nathanchance)
I may not respond right away but I will do my best to help you out. However,
I do expect you to put effort into learning this process, I am not here to hold
your hand. Please do not message me if you are building a ROM for a device
unofficially, I own a Nexus device, which means I never have to worry about
working with other's device tree. I have no knowledge that will help you and
I will ignore your message.
####################
# Special thanks #
####################
@Mazda-- for spearheading the Dirty Unicorns project, his dedication to
open source, and helping me out at random points during compilation.
@BeansTown106 for the various advice and guidance he has provided plus
his contributions to the open source community through the Pure Nexus Project.
@akhilnarang for his build environment scripts.
@npjohnson for the Ubuntu 16.04 Java 7 instructions.
# Copyright (C) 2016-2017 Nathan Chancellor
#
# This guide is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This guide is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment