Last updated: 2018-11-27
LineageOS is an alternate version of the Android operating system for your phone. Rather than building it yourself the first time, I recommend you use the image provided by invisblek. However, his image includes Google apps by default. If you want to experience life without Google's apps you will have to build LineageOS yourself. If you do choose to build it yourself, you can also install the Google apps at any time.
Moving from stock Android to LineageOS or back again will require restoring your phone to factory settings. YOU WILL LOSE ALL YOUR DATA. YOU MUST COPY ANYTHING YOU VALUE OFF OF THE PHONE.
LineageOS features still not working (most notable for me):
If you want to remove LineageOS and return to stock Android follow the instructions here:
Essential stock firmware and rom dumps
A quality USB cable and not the one provided with your phone.
Official TWRP 3.2.3-0 for Essential PH-1
This will take a lot of disk space. A repo sync with all the other tools that get downloaded will require 180 GB space by the time you are finished building.
All instructions assume you are running Linux. These instructions are for Ubuntu with minimum version of 16.04.
You will need to install proper ADB (Android Debugging Bridge) tools for your platform. For Ubuntu 18.04 this is as simple as running
sudo apt install adb
If your distribution provides out of date tools you can obtain them directly from Google.
Install the tools from Google:
unzip platform-tools-latest-linux.zip -d ~
To add these tools to your path add the following to ~/.profile
# add Android SDK platform tools to path
if [ -d "$HOME/platform-tools" ] ; then
Run the following command to update your shell:
Note that with Ubuntu 18.04 libesd0-dev is not available. Just delete the last item and install the rest of the tools.
sudo apt install bc bison build-essential ccache curl flex g++-multilib gcc-multilib git gnupg gperf imagemagick lib32ncurses5-dev lib32readline-dev lib32z1-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 libesd0-dev
Also install a Java Development Kit
sudo apt install openjdk-8-jdk
mkdir -p ~/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Note: You can use a base directory somewhere else. Mine is on a 240 GB SSD that I connect through a USB 3 enclosure.
mkdir -p ~/android/lineage
repo init -u https://github.com/LineageOS/android.git -b lineage-15.1
Note: mata is the code name for the Essential PH-1. If you see other tutorials for building LineageOS you can follow their instructions but use mata where necessary. I suggest you look up another tutorial since I am leaving out instructions on using ccache. Apparently it can speed up your build but I did not want to commit even more disk space to the project. My desktop has 32 GB of ram and I felt the build was fast enough.
jack is required for building android 8.1 and LineageOS 15.1.
Run the following command from your shell and add it to ~/.bashrc so it is set up for future use.
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"
If you want to build root into your LineageOS image then also run the following and also add it to ~./bashrc
We will use the muppets repository to bring in all the extra bits required for the mata build rather than obtain them from the phone itself.
Add the following bit to the file located at ~/android/lineage/.repo/local_manifests/roomservice.xml
<project name="TheMuppets/proprietary_vendor_essential" path="vendor/essential" />
In the future consider all of the above are things you don't have to do next time. Anytime you want to build just start here. You only have to run repo sync when you want to make sure you have the lastest code. We need to run it now to pull stuff in from the Muppets.
repo sync (on rebuilding I received error; see below)
repo sync error: Because of changes upstream, I had to rebuild using "repo sync --force-sync" (you will see this instructed in the output from the build), and "source build/envsetup.sh" before I could "croot".
Once you manage an error free build you can quickly go to the directory where your LineageOS image is located by typing this:cd $OUT
In the folder there is is a file named lineage-15.1-20180601-UNOFFICIAL-mata.zip. The name will be based on the date you built LineageOS.
There is also a boot.img that you can use to install Magisk if you want to gain root that way at a later time.
Installing LineageOS will require you have an unlocked boot loader. You only have to do this the first time.
If you are coming from stock you will have to wipe your phone with this command (it will ensure the phone is erased):
sudo fastboot -w
Settings - System - Developer options - USB debugging
Connect your phone to your computer with a USB cable and give your computer permission to do USB debugging with your phone.
Settings - Security - Screen Lock - None
If you forget to unlock your phone before you do the next steps you will have to reboot your phone and turn off the lock screen.
Type the following in your shell and wait for the phone to restart (your phone may prompt for permission):
sudo adb reboot-bootloader
To verify you can access the phone type:
sudo fastboot devices
If you see a device with the label "unathorized" you forgot to give your computer permission to access your phone through the adb interface.
sudo fastboot getvar current-slot
sudo fastboot set_active other
TWRP gets written to the boot partition.
sudo fastboot flash boot twrp-3.2.3-0-mata.img
sudo fastboot reboot
After a few moments TWRP will start.
We need to push the OS image to the phone (the exact filename may vary):
adb push lineage-15.1-date-UNOFFICIAL-mata.zip /sdcard/
This new version of TWRP can fail to allow touch input. If something goes wrong and you need to restart the phone depress the volume down button while the phone reboots.
You can just flash Lineage to it:
(NOTE: I had to unplug/replug my phone before each of these commands on upgrading. Hopefully digitizer works properly later.)
adb shell twrp sideload
adb sideload lineage-15.1-date-UNOFFICIAL-mata.zip
Otherwise there is a way to get digitizer to work at
If you want to root with Magisk you also need to push Magisk to the phone as above but with the correct filename version.
If you want to install gapps then download and push them to the phone as well.
Once TWRP starts slide the switch and press the INSTALL button.
Note: TWRP has a button to select if you want flash an .img or a .zip file. You have to use it to see the boot.img file and later the Magisk file on the /sdcard partion of your phone.
Note: In TWRP you need to use the back button as well as the interface buttons for navigation.
Use TWRP to select and flash the LineageOS image.
Use TWRP to select and install gapps if desired.
Use TWRP to select and install Magisk if desired.
There is no need to have TWRP installed as an app on your phone.
If digitizer is working you can use on screen commands to reboot. Otherwise "adb reboot bootloader" and press the power button to start the phone.
If you phone boot loops or takes more than a few minutes to start into LineageOS then boot to recovery and reset to factory.
To boot to recovery hold the volume up button down until the recovery menu appears. Use the volume buttons to select factory reset and the power button to execute. This will reset the phone and it will start properly.
Settings - System - Developer options - USB debugging
It is safest to keep USB debugging disabled until you need it. Go to the developer options menu in settings and disable it.
Settings - Security - Screen Lock