Compile LineageOS for Oneplus 3 on Fedora 25

Android community is one big cancerous clusterfuck, it is no wonder that finding a decent guide on how to compile Android from source written in a somewhat comprehensible english is pretty much mission impossible.
Cyanogenmod Inc. shutting down their wiki and services overnight surely didn’t help either.
Required packages on Fedora 25 are (rpmfusion repo must be previously installed):

$ sudo dnf install screen java-1.8.0-openjdk-devel git schedtool ncurses-devel ncurses-libs ncurses-compat-libs ImageMagick-devel libstdc++-devel bison gnupg lzma

For some reason the compilation process stores some temporary files in /tmp which, in Fedora 25, is mounted on a tmpfs ramdisk.
In case the ramdisk runs out of space for some retarded reason the build process instead of halting will go on like nothing happens and produce borked binaries as output.
To keep /tmp mounted on HDD run:

systemctl mask tmp.mount

Download the SDK (sdk-tools-linux) and extract the files, if building on an headless machine just get the command line tools: https://developer.android.com/studio/index.html#downloads

$ mkdir android-sdk-linux
$ mv sdk-tools-linux-3859397.zip
$ cd android-sdk-linux
$ unzip sdk-tools-linux-3859397.zip
$ vi ~/.bash_profile
---
export ANDROID_HOME=/home/user/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
---
$ source .bash_profile

Download the latest version of “Android SDK Tools”, “Android SDK Platform-tools”, “Android SDK Build-tools” and “SDK Plattform Android”:

### list available downloads
$ sdkmanager --list
$ sdkmanager "platform-tools" "tools"

Get repo utility and create a directory where Android’s source code will be downloaded.
Screen utility might come in handy since the download will likely take some time (it is around 60 GB).

$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir -p ~/android/system
$ cd android/system
### replace cm-14.1 with the desired branch
$ repo init -u git://github.com/LineageOS/android.git -b cm-14.1
$ repo sync

Now it is time to download the source code needed to compile for a specific device, which is a Oneplus 3 in my case.
Before actually compiling it is a good idea to run “make clobber” to clean the system from all the temp files created the previous time Android was compiled.
While this should not be necessary and makes the compilation procedure much longer it should ensure that everything is recompiled correctly every time even if some binary blobs have changed:

$ make clobber
$ source build/envsetup.sh
$ breakfast oneplus3

Double check that all the needed repository are actually present in roomservice.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <project name="LineageOS/android_device_oneplus_oneplus3" path="device/oneplus/oneplus3" remote="github" />
  <project name="LineageOS/android_device_oppo_common" path="device/oppo/common" remote="github" />
  <project name="LineageOS/android_kernel_oneplus_msm8996" path="kernel/oneplus/msm8996" remote="github" />
  <project name="LineageOS/android_packages_resources_devicesettings" path="packages/resources/devicesettings" remote="github" />
  <project name="LineageOS/android_vendor_nxp-nfc_opensource_frameworks" path="vendor/nxp-nfc/opensource/frameworks" remote="github" />
  <project name="LineageOS/android_vendor_nxp-nfc_opensource_libnfc-nci" path="vendor/nxp-nfc/opensource/libnfc-nci" remote="github" />
  <project name="LineageOS/android_vendor_nxp-nfc_opensource_Nfc" path="vendor/nxp-nfc/opensource/Nfc" remote="github" />
  <project name="LineageOS/android_device_qcom_common" path="device/qcom/common" remote="github" />
  <project name="LineageOS/android_external_sony_boringssl-compat" path="external/sony/boringssl-compat" remote="github" revision="cm-14.1" />
  <project name="LineageOS/android_external_stlport" path="external/stlport" remote="github" revision="cm-14.1" />
  <project name="TheMuppets/proprietary_vendor_oneplus" path="vendor/oneplus" remote="github" revision="cm-14.1" />
  <project name="TheMuppets/proprietary_vendor_qcom_binaries" path="vendor/qcom/binaries" remote="github" revision="cm-14.1" />
</manifest>

Google’s Android compilation guide suggest the user to enable gcc ccache, I prefer to keep it disabled because it can cause corrupted output (it already happened more than once to me).
Set jack server’s allocated memory (-Xmx flag) to as much RAM you can spare for it:

$ repo sync
#$ export USE_CCACHE=1
#$ prebuilts/misc/linux-x86/ccache/ccache -M 50G
$ export ANDROID_JACK_VM_ARGS="-Xmx8192m -Dfile.encoding=UTF-8 -XX:+TieredCompilation"
#set this environmental variable to include su binaries
$ export WITH_SU=true
$ brunch oneplus3

The compiled binaries can be found in ~/android/system/out/target/product/oneplus3/, it will all be compressed in an archive named “lineage-version-date-UNOFFICIAL-oneplus3” that can then be flashed from recovery.
The recovery everyone suggest to use for oneplus3 can be found here: https://forum.xda-developers.com/oneplus-3/development/recovery-twrp-3-0-2-0-touch-recovery-t3402999
This procedure can be extended to any other device, the only thing that needs adjustment are the repositories present in roomservice.xml file.
To compile LineageOS for a LG G3 for the european market (codename: d855) run repo sync, breakfast d855 and add the correct binary blob repository to roomservice.xml:

<project name="TheMuppets/proprietary_vendor_lge" path="vendor/d855" remote="github" revision="cm-14.1" />

d855 for some reason also needs lzma to compress the Linux kernel.

mafio
look at the "About me" page.

Leave a Comment

Your email address will not be published. Required fields are marked *