[Thinkpad Tablet General] Ecthelion4:
Introduction

After being a user of LineageOS for some years, I wanted to do the next step and also be able to create my own build of LOS. After some futile attempts I finally succeeded in building LOS 17.1 for the Lenovo Tab 4 10 Plus. Meanwhile even the fingerprint sensor is working, so that I think it's time to upload my builds somewhere and share them with others. In the meantime I thought it might be interesting for some out there to get a step by step instruction on how to build LOS for the Tab 4 10 Plus.

Part 1: Setting up Ubuntu 20.04 as build system

I'm a Windows user myself. Since building LOS (AFAIK) is requiring a Linux system for building (I tried with Windows Subsystem for Linux once but failed), I went for installing Ubuntu 20.04 inside a VM. VMWare Player is IMO a good choice because it's free and it allows routing USB devices to the guest system, so that it's even possible to use adb commands from within the Linux guest system and access an Android device attached via USB to the host. For this build of LOS this is not necessary, but it can be nice. But probably any VM software or, of course, a native Ubuntu 20.04 will do.

I used the following settings for the Ubuntu VM:

- 16 GB RAM

- 250 GB HDD (8 GB I used as swap space, the rest I gave to the mount point "/")

- USB compatibility I set to 3.1 and set the checkboxes for showing all USB devices and for sharing them with the VM

The above USB settings don't matter for the build. But with less RAM (inkl. swap) or less HDD space I had problems during my first attempts, even though I suspect that a bit less or RAM and HDD space might be possible. But with these settings you should be on the safe side. I opted for the full Ubuntu installation, because I did not want any tools missing that might be needed for the build. Perhaps the minimal installation would also do.

Part 2: Building LOS

There is an official documentation on how to build LOS (in this case for the device "bacon") which can be found here: https://wiki.lineageos.org/devices/bacon/build

During my first attempts of building LOS some of the commands, e.g. "repo sync" would initially fail. As far as I understood this is due to the "python" command missing in Ubuntu 20.04 after the initial setup. "python3" is available. So the first thing I did is adding a symlink "python" that points to python3:

sudo ln -s /usr/bin/python3 /usr/bin/python

After this we can follow the official LOS build documentation for some steps. So first download the Android platform tools from Google and then move to the directory where you downloaded the zip file to, e.g. via

cd Downloads

Next unzip the file (mind that the version no. inside the zip might need to get adjusted):

unzip platform-tools_r31.0.2-linux.zip -d ~

Like the build docs say we now need to add some lines to the file ~/.profile. So type

nano ~/.profile

This will start the nano editor. There right-click and paste the following lines and the end of the file:

# add Android SDK platform tools to path

if [ -d "$HOME/platform-tools" ] ; then

PATH="$HOME/platform-tools:$PATH"

fi

Then press Ctrl O, Enter and Ctrl X to save and exit and then make sure that the changes get used:

source ~/.profile

Next the documentation says that a couple of software packages need to get installed. As of writing this guide, this can be done via

sudo apt-get 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 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 libxml2-utils lzop pngcrush rsync schedtool squashfs-tools xsltproc zip zlib1g-dev

Afterwards some folders need to get created:

mkdir -p ~/bin

mkdir -p ~/android/lineage

Next the repo command needs to get downloaded and made executable:

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

chmod a+x ~/bin/repo

After this we again need to source the .profile file:

source ~/.profile

The ~/bin directory is already added to the path in the .profile of Ubuntu 20.04, so that there is no need to add it.

Next we need to setup the user email and name for the git commands. So replace the email address and name in the following commands:

git config --global user.email "you@example.com"

git config --global user.name "Your Name"

Now we can change to the LineageOS directory we created above and check out the code:

cd ~/android/lineage

repo init -u https://github.com/LineageOS/android.git -b lineage-17.1

repo sync

Next I set up the build environment via

source build/envsetup.sh

At this point we need to deviate from the official build documentation and create a file .repo/local_manifests/TBX704.xml with the specific configuration for the Tab 4 10 Plus:

mkdir .repo/local_manifests

nano .repo/local_manifests/TBX704.xml

Then paste the following XML code into this file, then use Ctrl O, Enter and Ctrl X to save and exit:

<?xml version="1.0" encoding="UTF-8"?>

<manifest>

<project name="LineageOS/android_device_lenovo_TB8703" path="device/lenovo/TB8703" remote="github" />

<project name="LineageOS/android_device_lenovo_TB8704" path="device/lenovo/TB8704" remote="github" />

<project name="LineageOS/android_device_lenovo_TBX704" path="device/lenovo/TBX704" remote="github" />

<project name="LineageOS/android_device_lenovo_tb-common" path="device/lenovo/tb-common" remote="github" />

<project name="lenovo-devs/android_kernel_lenovo_msm8953" path="kernel/lenovo/msm8953" remote="github" />

<!-- Vendor -->

<project name="lenovo-devs/proprietary_vendor_lenovo" path="vendor/lenovo" remote="github" revision="lineage-17.1-gxfp" />

</manifest>

Afterwards I again executed

source build/envsetup.sh

Not sure if the last one is needed, but it won't hurt. In the same way I'm not sure whether the following repo sync -c is necessary or whether we might have skipped the repo sync above and only use the following command, but I did

repo sync -c

Now we are ready to prepare the build for the Lenovo Tab 4 10 Plus and then start the build.

lunch lineage_TBX704-userdebug

mka bacon

This will take some hours. You might have noticed that I skipped setting up ccache, which is done in the official documentation. This is not a necessary but an optional step. For the first build this won't matter. For subsequent builds activating ccache might speed up the build. But it also uses up some space on the hard drive (the recommendation in the build docs is 50GB, or 20GB when activating compression). Once the build was finished successfully, you should find the zip file with the LOS image in out/target/product/TBX704/.