Note This guide contains parts that are specific to building CyanogenMod for the OnePlus 3, do read the commands and make necessary adjustments for different devices. Do NOT try to install CyanogenMod built from this guide on any other phone, it may lead to a bricked device!
Let's update up the apt lists first,
Install specific build tools,
apt-get install bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop maven openjdk-7-jdk pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev bc
Note if using a 64bit build of Ubuntu, You'll also need to install,
apt-get install g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev
Note if building on Ubuntu 16.04
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
CyanogenMod 13 requires OpenJDK 1.7 (Java 7) to be built. We'll need to install this as well,
apt-get install openjdk-7-jre openjdk-7-jdk
Create the folder you'll be downloading the source code into,
mkdir -p ~/android/system
Download the "repo" tool, the repo tool is used to download and sync the source code,
curl https://storage.googleapis.com/git-repo-downloads/repo > /bin/repo chmod a+x /bin/repo
Enter into the Source code directory and initialize the repository,
cd ~/android/system/ repo init -u https://github.com/CyanogenMod/android.git -b cm-13.0
To download the CyanogenMod source code, run the following command,
This step will take a while as it downloads around ~35 - 40 GB of data, I'd recommend using a Virtual Machine at a cloud/VM provider or a machine with a high speed internet connection to proceed.
In this guide, I'm building CyanogenMod for the OnePlus 3, so I use the device name "oneplus3" here to specify building CyanogenMod for the OnePlus 3
source build/envsetup.sh breakfast oneplus3
Edit the roomservice.xml file to ensure it has all the correct repos listed,
And make sure it contains the following,
<?xml version="1.0" encoding="UTF-8"?> <manifest> <project name="CyanogenMod/android_device_oneplus_oneplus3" path="device/oneplus/oneplus3" remote="github" /> <project name="CyanogenMod/android_device_oppo_common" path="device/oppo/common" remote="github" /> <project name="CyanogenMod/android_kernel_oneplus_msm8996" path="kernel/oneplus/msm8996" remote="github" /> <project name="CyanogenMod/android_vendor_nxp-nfc_opensource_frameworks" path="vendor/nxp-nfc/opensource/frameworks" remote="github" /> <project name="CyanogenMod/android_vendor_nxp-nfc_opensource_libnfc-nci" path="vendor/nxp-nfc/opensource/libnfc-nci" remote="github" /> <project name="CyanogenMod/android_vendor_nxp-nfc_opensource_Nfc" path="vendor/nxp-nfc/opensource/Nfc" remote="github" /> <project name="CyanogenMod/android_device_qcom_common" path="device/qcom/common" remote="github" /> <project name="TheMuppets/proprietary_vendor_oneplus" path="vendor/oneplus" remote="github" revision="cm-13.0" /> </manifest>
The "TheMuppets/proprietary_vendor_oneplus" line is important, as it contains all the proprietary blobs for the OnePlus 3.
Save the file and then run a sync again,
cd ~/android/system/ repo sync
It shouldn't take long this time as it only downloads the missing proprietary blobs.
This is highly recommended by CyanogenMod, to reduce the amount of time taken for the build,
export USE_CCACHE=1 prebuilts/misc/linux-x86/ccache/ccache -M 50G
I usually build it under a "screen" as I'm building it off of a remote machine, so SSH disconnects don't affect the build. So let's enter into a "screen",
Finally, start building CyanogenMod,
The initial build will take sometime to complete, around 35 - 40 minutes is what it took me. You can "detach" from the screen by hitting CTRL+A+D and then "reconnect" to the screen with the command "screen -r". Detaching from the screen will not affect the building process, it will continue in the background.