Soo you want to build LineageOS (los) for your xiaomi davinci?
This guide will show you how! In this guide i'll lead you through the process of compiling los 17.1 for xiaomis MI 9T, optionally with spoofing support for microG.
I am not responsible for any damage you do to your phone and this guide does not claim to be perfect or in any way complete. Proceed at your own risk.
ALSO! I am not any kind of android or los guru, i am just a guy who trial and errored his way to a flashable (and bootable) zip file. Don't expect this to give you super human powers!1!!!11!elf!.
You could also use this guide to create a docker container, i don't know and i don't really care.
You have at least non shitty hardware and at least a non shitty internet connection. I mean like at LEAST 6GB RAM, 4 decent CPU cores and (i needed) 187GB storage for the sources and the build, better aim for 250GB free space.
I assume you know the basics of a unix like shell and know how to handle simple
commands like ls
, cd
, and so on.
I also assume you are running a debian based operating system. For debian at least buster, for ubuntu at least 18.04.
I assume you know the basics about git/repo, or at least what you use them for.
General knowledge about software/ how to use a computer is welcome.
In order to build, you'll have to install some packages. To be specific, you'll need those packages:
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 \
libwxgtk3.0-gtk3-dev \
libxml2 \
libxml2-utils \
lzop \
pngcrush \
repo \
rsync \
schedtool \
squashfs-tools \
xsltproc \
zip \
zlib1g-dev
So simply open a terminal and type in sudo apt update && sudo apt install
and then just paste the above lines in there, hit enter and you should be good
to go.
The second thing you will have to install the repo
command.
If you are on a ubuntu based distro, good for you, just install the repo
package with apt.
If you are on debian you'll have to download repo
from google:
$ sudo curl \
https://storage.googleapis.com/git-repo-downloads/repo \
-o /usr/bin/repo
$ sudo chmod 755 /usr/bin/repo
You'll need to set a git name and email for smooth repopicking.
$ git config --global user.name "Your Name"
$ git config --global user.email [email protected]
This placeholders should do if you don't want to push your commits.
First, create a work directory, which in my case is android
, then cd into it,
initialize and clone the lineage os source.
Now there are two ways to approach the init part, either you can clone the full repo (I'd recommend that if you want to customize shit afterwards) or you can shallow clone the stuff (if you just want to build fast and stock).
The first approach will take (depending on your internet speed) a shitton of time, as the source is about 90 Gigs for me at the time of April 2020.
I didn't really try the second approach, but i heard, that it is way smaller
(this sentence needs clarification!). If you are trying to apply many changes
afterwards (using repopick
), it will download all needed commits (sometimes
several gigabytes), so it'll take longer at a later time.
$ # create dirs
$ mkdir -p ~/android
$ cd ~/android
$ # Use the following method to do a FULL clone
$ repo init -u https://github.com/LineageOS/android.git -b lineage-17.1
$ # or the following to do a shallow clone
$ repo init -u https://github.com/LineageOS/android.git \
-b lineage-17.1 --depth=1
$ # Sync the repo (this is the step that takes a long time)
$ repo sync -c --force-sync
$ # You can make use of proxies like this
$ http_proxy="socks5://localhost:8888" https_proxy="socks5://localhost:8888" repo sync -c --force-sync
And now you should have the los sources, well done.
So it gets interesting. For some background (this is mainly from what i understand, i could be totally wrong...): The android build system relies heavily on xml files that describe which repo has to go to which path. So if you have your sources, you can add xml files containing some more repos and where they have to be put and afterwards the build system can make use of them by compiling them into the ROM you are about to create.
For the davinci, we are going to take the xml file from here.
I don't know about you, but i had to adjust the file for me to work. I forked and modified it you can find my fork here.
I also removed the two last lines, as i don't want google products on my smartphone.
Anyway, you'll have to put the file into ~/android/.repo/local_manifests/
so
repo
can "see" the file and make use of it. Make sure to run a repo sync -c --force-sync
after you put the file there.
$ cd ~/android
$ mkdir -p .repo/local_manifests/
$ curl \
https://raw.githubusercontent.com/cheriimoya/manifest/lineage-17.1/extra_packages.xml \
-o .repo/local_manifests/extra_packages.xml
$ repo sync -c --force-sync
This step is completely optional. If you don't know what signature spoofing is, skip it or google it.
I honestly don't know which steps are necessary, i simply read the "official" docker source.
The following will add signature spoofing support and the prebuilt microG and F-Droid applications.
So simply follow them, i don't think it will hurt.
I first added the prebuilt apks to the local_manifests
and added them to the
build:
$ cd ~/android
$ curl \
https://raw.githubusercontent.com/cheriimoya/manifest/lineage-17.1/prebuilt_apks.xml \
-o .repo/local_manifests/prebuilt_apks.xml
$ repo sync -c --force-sync
$ mkdir -p "vendor/lineage/overlay/microg"
$ sed -i "1s;^;PRODUCT_PACKAGE_OVERLAYS := vendor/lineage/overlay/microg\n;" \
"vendor/lineage/config/common.mk"
$ export CUSTOM_PACKAGES="GmsCore GsfProxy FakeStore MozillaNlpBackend \
NominatimNlpBackend com.google.android.maps.jar FDroid \
FDroidPrivilegedExtension "
$ sed -i "1s;^;PRODUCT_PACKAGES += $CUSTOM_PACKAGES\n\n;" \
"vendor/lineage/config/common.mk"
Next, we'll download and apply the spoofing patch for android Q:
$ cd ~
$ curl -O \
https://raw.githubusercontent.com/leonghui/docker-lineage-cicd/lineage-17.0/src/signature_spoofing_patches/android_frameworks_base-Q.patch
$ curl -O \
https://raw.githubusercontent.com/lineageos4microg/docker-lineage-cicd/master/src/signature_spoofing_patches/frameworks_base_config.xml
$ cd ~/android/frameworks/base
$ # This step is optional (otherwise all apps can spoof their signature)
$ sed -i \
's/android:protectionLevel="dangerous"/android:protectionLevel="signature|privileged"/' \
~/android_frameworks_base-Q.patch
$ cd ~/android/frameworks/base
$ git apply ~/android_frameworks_base-Q.patch
$ git add .
$ git commit -m 'android_frameworks_base-Q.patch'
$ cd ../..
$ mkdir -p "vendor/lineage/overlay/microg/frameworks/base/core/res/res/values/"
$ cp ~/frameworks_base_config.xml "vendor/lineage/overlay/microg/frameworks/base/core/res/res/values/config.xml"
The only things i applied from pigs update script are the first few lines:
$ cd ~/android
$ source ./build/envsetup.sh
$ repopick -t ten-camera-api2-fix
$ repopick -t ten-popup-cam
This is the part where you can apply the wildest customisations, feel free to apply all the changes the los gerrit has to offer!
Just add the changes with:
$ repopick -P <path_to_target_repo> <change_no_1> <change_no_2>
If you mess something up, you can always reset all repos by running repo sync -d
in the ~/android
directory.
The whole preparation part is over and we can finally build! This step is pretty simple, it should be enough to follow these steps:
$ cd ~/android
$ source build/envsetup.sh
$ croot
$ brunch davinci
The zip file should be in the ~/android/out/target/product/davinci/
directory.
Just comment improvements.
I probably don't have the time to help everyone, please try to fix your problem by yourself first.
I think that the microg overlay part is not needed for davinci since it does not touch config_enableNetworkLocationOverlay or config_enableFusedLocationOverlay. So I think that you could delete the following lines:
I have not tried it yet, so maybe I am wrong.