Skip to content

Instantly share code, notes, and snippets.

@iykex
Created April 11, 2018 23:29
Show Gist options
  • Save iykex/312e1a1e2dcc20e36589cbee604c061d to your computer and use it in GitHub Desktop.
Save iykex/312e1a1e2dcc20e36589cbee604c061d to your computer and use it in GitHub Desktop.
Step To Compiling LineageOS `14.1` ROM From Source

Step To Compiling LineageOS 14.1 ROM From Source


Install the build packages :

To build LineageOS, you’ll need:

  • sudo apt install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-dev libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libssl-dev libwxgtk3.0-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev

For Ubuntu versions older than 16.04 (xenial), substitute:

  • libwxgtk3.0-dev → libwxgtk2.8-dev

Java

Different versions of LineageOS require different JDK (Java Development Kit) versions.

  • LineageOS 14.1-15.1: need OpenJDK 1.8
sudo apt install openjdk-8-jdk
sudo apt install openjdk-8-jre



Create the directories

You’ll need to set up some directories in your build environment.

To create them:

mkdir -p ~/bin 
mkdir -p ~/android/lineage

The ~/bin directory will contain the git-repo tool (commonly named “repo”) and the ~/android/lineage directory will contain the source code of LineageOS.

Install the repo command

Enter the following to download the repo binary and make it executable (runnable):

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo 
chmod a+x ~/bin/repo
Put the ~/bin directory in your path of execution

In recent versions of Ubuntu, ~/bin should already be in your PATH. You can check this by opening ~/.profile with a text editor and verifying the following code exists (add it if it is missing):

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

Then, run source ~/.profile to update your environment.




Getting Started.

Initialize the LineageOS source repository

  • cm-14.1

Enter the following to initialize the repository:

cd ~/android/lineage
repo init -u git://github.com/LineageOS/android.git -b cm-14.1
Download the source code

To start the download of the source code to your computer, type the following:

repo sync



Prepare the device-specific code

After the source downloads, ensure you’re in the root of the source code (cd ~/android/lineage), then clone your device sources with the following commands :

device tree :

git clone https://github.com/DhirajSurvase/android_device_Moto-C-plus -b cm-14.1 device/moto/panelli

kernel source :

git clone https://github.com/DhirajSurvase/kernel-Moto-C-plus -b cm-14.1 kernel/moto/panelli

vendor blobs :

git clone https://github.com/DhirajSurvase/android-vendor-Moto-C-plus -b cm-14.1 vendor/moto/panelli

then type:

	source build/envsetup.sh 
# set up the Moto C-plus code
 	lunch lineage_panelli userdebug 
# To Build the `ROM`(Lineage 14.1)
	croot
	brunch panelli 



Turn on caching to speed up build

Make use of ccache if you want to speed up subsequent builds by running:

export USE_CCACHE=1

and adding that line to your ~/.bashrc file. Then, specify the maximum amount of disk space you want ccache to use by typing this:

ccache -M 50G

where 50GB corresponds to 50GB of cache. This needs to be run once. Anywhere from 25GB-100GB will result in very noticeably increased build speeds (for instance, a typical 1hr build time can be reduced to 20min). If you’re only building for one device, 25GB-50GB is fine. If you plan to build for several devices that do not share the same kernel source, aim for 75GB-100GB. This space will be permanently occupied on your drive, so take this into consideration. See more information about ccache on Google’s Android build environment initialization page.

You can also enable the optional ccache compression. While this may involve a slight performance slowdown, it increases the number of files that fit in the cache. To enable it, run:

export CCACHE_COMPRESS=1

or add that line to your ~/.bashrc file.

Note: If compression is enabled, the ccache size can be lower (aim for approximately 20GB for one device).

Configure jack

Jack is the currently used Java toolchain for building LineageOS 14.1 and up. It is known to run out of memory often if not configured correctly - a simple fix is to run this command:

export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"

Adding that command to your ~/.bashrc file will automatically configure Jack to allocate a sufficient amount of memory (in this case, 4GB).

Start the build
	source build/envsetup.sh 
# set up the Moto C-plus code
 	lunch lineage_panelli userdebug 
# To Build the `ROM`(Lineage 14.1)
	croot
	brunch panelli 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment