[ROM][Android 8/9/10][Unofficial] LineageOS for Mi-4c/Mi-4s

silverchairbg

Senior Member
May 13, 2012
96
10
8
@WJXXBSH I've already tried and it failed with unsufficient space. I've managed to enable root access from developer option, but when I start built-in "File Manager", it still doesn't see anything in "/system" folder besides /tmp. How do I access "/system/fonts" in order to delete those chinese/korean fonts I am not using?

Thanks
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
@WJXXBSH I've already tried and it failed with unsufficient space. I've managed to enable root access from developer option, but when I start built-in "File Manager", it still doesn't see anything in "/system" folder besides /tmp. How do I access "/system/fonts" in order to delete those chinese/korean fonts I am not using?

Thanks
The built-in "Files" app is obviously not support root operations (because it's developed by Google). As a solution, install some other file manager app (Solid Explorer, Mixplorer, Root Explorer...) you prefer, or just reboot into recovery and use "Advanced - File manager" to delete any files you want (remember to mount "/system" in "Mount" first). A factory reset (wipe "/data" except "/data/media") might be needed to make GAPPs work properly.
 
Last edited:

ciberfred

New member
Dec 16, 2019
3
0
0
last update reboot multiple time a day

the last update flashed on my phone and get multiple reboot a day. But the screen responses is better than the build at begin of the year :) is need to flash the new kernel provided in few previous comments to solve this issue ?
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
the last update flashed on my phone and get multiple reboot a day. But the screen responses is better than the build at begin of the year :) is need to flash the new kernel provided in few previous comments to solve this issue ?
Do you mean you had updated the rom from an ancient version (at the beginning of this year) to the latest one? If true, try a factory reset (wipe "/data" without "/data/media" + wipe "/system") and reinstall the latest rom again. Please also tell me if you had GAPPs or some Magisk modules installed.
The new kernel image on GitHub is just a nightly build of the latest kernel sources. If you like, feel free to install it (I always test the rom and kernel on my own device before uploading them).
 
Last edited:

ciberfred

New member
Dec 16, 2019
3
0
0
Do you mean you had updated the rom from an ancient version (at the beginning of this year) to the latest one? If true, try a factory reset (wipe "/data" without "/data/media" + wipe "/system") and reinstall the latest rom again. Please also tell me if you had GAPPs or some Magisk modules installed.
The new kernel image on GitHub is just a nightly build of the latest kernel sources. If you like, feel free to install it (I always test the rom and kernel on my own device before uploading them).
The update bootloop the android startup image. juste wipe all and install it (remove some font files to have enough room to install gapp pico). then added what'sapp, facebook ,gphoto and messenger app from store.
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
hello does it work on mi 4s and which custom recovery is being used
Most Mi-4c roms should also work on Mi-4s, but I'm not sure if fingerprint or external sdcard works properly. For TWRP recovery, just use the same one for Mi-4c. Please note that your device needs to be unlocked before installing custom roms or recovery.
 

xammy

Member
Dec 10, 2008
19
0
21
Most Mi-4c roms should also work on Mi-4s, but I'm not sure if fingerprint or external sdcard works properly. For TWRP recovery, just use the same one for Mi-4c. Please note that your device needs to be unlocked before installing custom roms or recovery.
I've seen there's already version 18.1 in github (https://github.com/WJXXBSH/android_device_xiaomi_libra/tree/lineage-18.1)
is it stable yet?

just an idea, perhaps to minimalize system storage usage, you could remove apps like browsers, calendars, and email. most users preferred their own favourite apps for this
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
I've seen there's already version 18.1 in github (https://github.com/WJXXBSH/android_device_xiaomi_libra/tree/lineage-18.1)
is it stable yet?

just an idea, perhaps to minimalize system storage usage, you could remove apps like browsers, calendars, and email. most users preferred their own favourite apps for this
Not yet, there are still some issues need to be resolved currently. I'm kind of busy this month, so my work about Lineage roms might be slower to leave more time for myself.

I have removed many unneeded things (not only apps) from the rom since lineage-16.0, but apps like the default Browser and Clock are necessary for new users, I need to keep them as is. The Noto fonts take a lot free space in system partition, if Chinese/Japanese/Korean is not your main language, just delete "fonts/NotoSansCJK.ttc" to save 114MB. If you're using Google Webview (Android System Webfiew in Play Store) instead of the prebuit one, you could also delete "product/app/webview" to save another 150MB.
 

xammy

Member
Dec 10, 2008
19
0
21
Not yet, there are still some issues need to be resolved currently. I'm kind of busy this month, so my work about Lineage roms might be slower to leave more time for myself.

I have removed many unneeded things (not only apps) from the rom since lineage-16.0, but apps like the default Browser and Clock are necessary for new users, I need to keep them as is. The Noto fonts take a lot free space in system partition, if Chinese/Japanese/Korean is not your main language, just delete "fonts/NotoSansCJK.ttc" to save 114MB. If you're using Google Webview (Android System Webfiew in Play Store) instead of the prebuit one, you could also delete "product/app/webview" to save another 150MB.
First, i would like to thank you for your fast response.
I've been testing your rom for couple days and this is the best i've experience with 2GB Ram so far.
Sadly, for asians, CJK fonts is a must have, otherwise we cannot display the text. so here's my workaround:
  • Flash your ROM
  • Install CX Explorer (or any who can backup apk)
  • Do apk backup:
    • Contacts (just contacts.apk)
    • Calculator
    • Recorder
    • Clock
    • Browser
    • Calendar (just calendars.apk)
    • Music
  • Reboot to TWRP
    • Mount System R/W, delete those apps in File Manager
    • Install Gapps Pico
  • Reboot and reinstall apps above as user (or simply install other apps as preferred)
So basically, what you have in the system is just Phone, Messaging, Camera, Files, Gallery and Settings plus Play Store, and this leaves me around 46mb free (2%) but its enough.
If you added included Webview to remove and replace with Google Webview, this will give another space to play.
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
First, i would like to thank you for your fast response.
I've been testing your rom for couple days and this is the best i've experience with 2GB Ram so far.
Sadly, for asians, CJK fonts is a must have, otherwise we cannot display the text. so here's my workaround:
  • Flash your ROM
  • Install CX Explorer (or any who can backup apk)
  • Do apk backup:
    • Contacts (just contacts.apk)
    • Calculator
    • Recorder
    • Clock
    • Browser
    • Calendar (just calendars.apk)
    • Music
  • Reboot to TWRP
    • Mount System R/W, delete those apps in File Manager
    • Install Gapps Pico
  • Reboot and reinstall apps above as user (or simply install other apps as preferred)
So basically, what you have in the system is just Phone, Messaging, Camera, Files, Gallery and Settings plus Play Store, and this leaves me around 46mb free (2%) but its enough.
If you added included Webview to remove and replace with Google Webview, this will give another space to play.
Converting system apps to user ones is certainly a solution (if there is a "classes.dex" inside APK). I once seen someone installed GAPPs as user apps and it worked properly, you could also try this way. As Google is blocked in China, I don't install GAPPs to my device so I could keep all necessary apps as well as the fonts in system partition. I think just removing the webview (then install Google Webview as user app) should provide enough space for GAPPs, even without deleting other apps.
 
Last edited:

d7791

New member
Dec 30, 2020
4
0
1
Hi WJXXBSH,

First of all thank you for all the good work and the time put into building this image!

I got a hold of an old Mi 4c and would like to help testing and maybe further developing 17.1/18.0 image. I flashed 17.1 image to the device, but what I would really like to do is to compile the stuff by myself. I figured out I need to modify the local manifest file and add your repositories, but when I start the build I get some errors (related to camera). Before digging in the wrong directoion, I would like to make sure that I am doing the right thing with the build. Would you be so nice and point me to the document which describes how to build lineage 17.1 with your kernel/device/vendor files. Could be you already wrote something like that and I missed (or maybe it is so simple that I am missing the obvious).

Thanks!
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
Hi WJXXBSH,

First of all thank you for all the good work and the time put into building this image!

I got a hold of an old Mi 4c and would like to help testing and maybe further developing 17.1/18.0 image. I flashed 17.1 image to the device, but what I would really like to do is to compile the stuff by myself. I figured out I need to modify the local manifest file and add your repositories, but when I start the build I get some errors (related to camera). Before digging in the wrong directoion, I would like to make sure that I am doing the right thing with the build. Would you be so nice and point me to the document which describes how to build lineage 17.1 with your kernel/device/vendor files. Could be you already wrote something like that and I missed (or maybe it is so simple that I am missing the obvious).

Thanks!
I will write some documents about how to build Lineage ROMs on Mi-4c (with my device/kernel/vendor) later, wait me for some time (maybe days later).

If you have put my device/kernel/vendor into right place (like ./xxx/xiaomi/libra), it should work when you are trying to execute . build/envsetup.sh && lunch lineage_libra-userdebug in the root directory of your lineage-17.1 repos. However, a few build errors may happen due to some hacks in my device configs (eg. dex2oat). If you meet these errors, please refer to repo_17.diff and take the necessary changes in project build/make/ (not all of them is needed unless you want to build a rom like my releases with "user" build variant).

Also, please check your local_manifest and make sure it has (at least) the following items:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <project name="WJXXBSH/android_device_xiaomi_libra" path="device/xiaomi/libra" remote="github" revision="lineage-17.1" />
  <project name="WJXXBSH/android_kernel_xiaomi_libra" path="kernel/xiaomi/libra" remote="github" revision="master" />
  <project name="WJXXBSH/android_vendor_xiaomi_libra" path="vendor/xiaomi/libra" remote="github" revision="lineage-16.0" />
  <project name="LineageOS/android_hardware_sony_timekeep" path="hardware/sony/timekeep" remote="github" revision="lineage-17.1" />
  <project name="LineageOS/android_hardware_xiaomi" path="hardware/xiaomi" remote="github" revision="lineage-17.1" />
</manifest>
 

d7791

New member
Dec 30, 2020
4
0
1
I will write some documents about how to build Lineage ROMs on Mi-4c (with my device/kernel/vendor) later, wait me for some time (maybe days later).

If you have put my device/kernel/vendor into right place (like ./xxx/xiaomi/libra), it should work when you are trying to execute . build/envsetup.sh && lunch lineage_libra-userdebug in the root directory of your lineage-17.1 repos. However, a few build errors may happen due to some hacks in my device configs (eg. dex2oat). If you meet these errors, please refer to repo_17.diff and take the necessary changes in project build/make/ (not all of them is needed unless you want to build a rom like my releases with "user" build variant).

Also, please check your local_manifest and make sure it has (at least) the following items:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <project name="WJXXBSH/android_device_xiaomi_libra" path="device/xiaomi/libra" remote="github" revision="lineage-17.1" />
  <project name="WJXXBSH/android_kernel_xiaomi_libra" path="kernel/xiaomi/libra" remote="github" revision="master" />
  <project name="WJXXBSH/android_vendor_xiaomi_libra" path="vendor/xiaomi/libra" remote="github" revision="lineage-16.0" />
  <project name="LineageOS/android_hardware_sony_timekeep" path="hardware/sony/timekeep" remote="github" revision="lineage-17.1" />
  <project name="LineageOS/android_hardware_xiaomi" path="hardware/xiaomi" remote="github" revision="lineage-17.1" />
</manifest>
Hi,

Thanks for the quick answer!

So what I did was the following:

1) Follow the steps from here: whyred build till and including:
Code:
repo init -u https://github.com/LineageOS/android.git -b lineage-17.1
2) mkdir -p .repo/local_manifests and I created a file containing your xml sources.

3) repo sync

4) source build/envsetup.sh && lunch lineage_libra-userdebug

That failed. Afterwhich I applied patches to build/make project and did

5) lunch lineage_libra-userdebug && m

After which the build starts but the compilation of kernel fails:

Code:
ccache: error: Could not find compiler "clang" in PATH
make[3]: *** [/android/lineage/kernel/xiaomi/libra/scripts/Makefile.build:286: scripts/mod/empty.o] Error 1
make[3]: *** Waiting for unfinished jobs....
  Using /android/lineage/kernel/xiaomi/libra as source for kernel
make[2]: *** [/android/lineage/kernel/xiaomi/libra/scripts/Makefile.build:527: scripts/mod] Error 2
make[1]: *** [/android/lineage/kernel/xiaomi/libra/Makefile:525: scripts] Error 2
make: *** [Makefile:126: sub-make] Error 2
make: Leaving directory '/android/lineage/kernel/xiaomi/libra'
19:11:24 ninja failed with: exit status 1
I have to add I compiled for the whyred before without any issues. Maybe I messed up with patches?!

Btw. After I get this working I can put the exact steps in one post and share them here if you like.
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
Hi,

Thanks for the quick answer!

So what I did was the following:

1) Follow the steps from here: whyred build till and including:
Code:
repo init -u https://github.com/LineageOS/android.git -b lineage-17.1
2) mkdir -p .repo/local_manifests and I created a file containing your xml sources.

3) repo sync

4) source build/envsetup.sh && lunch lineage_libra-userdebug

That failed. Afterwhich I applied patches to build/make project and did

5) lunch lineage_libra-userdebug && m

After which the build starts but the compilation of kernel fails:

Code:
ccache: error: Could not find compiler "clang" in PATH
make[3]: *** [/android/lineage/kernel/xiaomi/libra/scripts/Makefile.build:286: scripts/mod/empty.o] Error 1
make[3]: *** Waiting for unfinished jobs....
  Using /android/lineage/kernel/xiaomi/libra as source for kernel
make[2]: *** [/android/lineage/kernel/xiaomi/libra/scripts/Makefile.build:527: scripts/mod] Error 2
make[1]: *** [/android/lineage/kernel/xiaomi/libra/Makefile:525: scripts] Error 2
make: *** [Makefile:126: sub-make] Error 2
make: Leaving directory '/android/lineage/kernel/xiaomi/libra'
19:11:24 ninja failed with: exit status 1
I have to add I compiled for the whyred before without any issues. Maybe I messed up with patches?!

Btw. After I get this working I can put the exact steps in one post and share them here if you like.
My kernel is set to build with clang by default, so you should install clang package in your system (depend on which Linux distribution you are using). I can only confirm that clang-11 is able to build a kernel without issues, higher version should also work. The kernel sources are compiled by clang, but will be linked by ld (inside gcc toolchains) with llvm plugin (provides by clang).

Here are the configs which work properly on Ubuntu 20.10+, without installing gcc-10 (the prebuilt ld inside gcc-4.9 in AOSP sources will be used). You can change TARGET_KERNEL_CLANG_PATH to the real path in your system if needed.
Makefile:
# Kernel
BOARD_KERNEL_BASE := 0x00000000
BOARD_KERNEL_CMDLINE := androidboot.hardware=qcom androidboot.selinux=permissive ehci-hcd.park=3 msm_rtb.filter=0x37
BOARD_KERNEL_IMAGE_NAME := Image.gz-dtb
BOARD_KERNEL_PAGESIZE := 4096
TARGET_KERNEL_ARCH := arm64
TARGET_KERNEL_CLANG_COMPILE := true
TARGET_KERNEL_CLANG_PATH := /lib/llvm-11
TARGET_KERNEL_CLANG_VERSION := 11.0
TARGET_KERNEL_CONFIG := libra_defconfig
TARGET_KERNEL_CROSS_COMPILE_PREFIX := aarch64-linux-gnu-
TARGET_KERNEL_HEADER_ARCH := arm64
TARGET_KERNEL_SOURCE := kernel/xiaomi/libra
There is also a easier way to replace your step "5", try brunch lineage_libra-userdebug instead. If you want to test kernel building more efficiently, try make bootimage instead of making all targets.
 
Last edited:

d7791

New member
Dec 30, 2020
4
0
1
My kernel is set to build with clang by default, so you should install clang package in your system (depend on which Linux distribution you are using). I can only confirm that clang-11 is able to build a kernel without issues, higher version should also work. The kernel sources are compiled by clang, but will be linked by ld (inside gcc toolchains) with llvm plugin (provides by clang).
I am on 20.04 so the available clange is v10. I did: "sudo apt install clang gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi llvm-dev" (llvm-dev is needed because of LLVMgold.so).

Here are the configs which work properly on Ubuntu 20.10+, without installing gcc-10 (the prebuilt ld inside gcc-4.9 in AOSP sources will be used). You can change TARGET_KERNEL_CLANG_PATH to the real path in your system if needed.
Makefile:
# Kernel
BOARD_KERNEL_BASE := 0x00000000
BOARD_KERNEL_CMDLINE := androidboot.hardware=qcom androidboot.selinux=permissive ehci-hcd.park=3 msm_rtb.filter=0x37
BOARD_KERNEL_IMAGE_NAME := Image.gz-dtb
BOARD_KERNEL_PAGESIZE := 4096
TARGET_KERNEL_ARCH := arm64
TARGET_KERNEL_CLANG_COMPILE := true
TARGET_KERNEL_CLANG_PATH := /lib/llvm-11
TARGET_KERNEL_CLANG_VERSION := 11.0
TARGET_KERNEL_CONFIG := libra_defconfig
TARGET_KERNEL_CROSS_COMPILE_PREFIX := aarch64-linux-gnu-
TARGET_KERNEL_HEADER_ARCH := arm64
TARGET_KERNEL_SOURCE := kernel/xiaomi/libra
There is also a easier way to replace your step "5", try brunch lineage_libra-userdebug instead. If you want to test kernel building more efficiently, try make bootimage instead of making all targets.
In /android/lineage/device/xiaomi/libra/BoardConfig.mk I had to replace CLANG_PATH and CLANG_VERSION:
TARGET_KERNEL_CLANG_PATH := /lib/llvm-10
TARGET_KERNEL_CLANG_VERSION := 10.0

After that compilation succeeded (brunch lineage_libra-userdebug).

As I now have all the needed steps would you like me to send them to you so you can stick them to one of the front posts?

The other topic - frequent reboots - I've noticed device reboots frequently with this build. I've noticed the same behaviour with lineage-17.1-20201216-UNOFFICIAL-libra.zip but the lineage-17.1-20201112-UNOFFICIAL-libra.zip is stable as a rock. Do you know what changed between these two? I imagine it was something with the kernel. (along the way, my device is 16G/2G).
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
I am on 20.04 so the available clange is v10. I did: "sudo apt install clang gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi llvm-dev" (llvm-dev is needed because of LLVMgold.so).



In /android/lineage/device/xiaomi/libra/BoardConfig.mk I had to replace CLANG_PATH and CLANG_VERSION:
TARGET_KERNEL_CLANG_PATH := /lib/llvm-10
TARGET_KERNEL_CLANG_VERSION := 10.0

After that compilation succeeded (brunch lineage_libra-userdebug).

As I now have all the needed steps would you like me to send them to you so you can stick them to one of the front posts?

The other topic - frequent reboots - I've noticed device reboots frequently with this build. I've noticed the same behaviour with lineage-17.1-20201216-UNOFFICIAL-libra.zip but the lineage-17.1-20201112-UNOFFICIAL-libra.zip is stable as a rock. Do you know what changed between these two? I imagine it was something with the kernel. (along the way, my device is 16G/2G).
If you also installed gcc-aarch64 and gcc-arm on your computer, it's recommended to set TARGET_KERNEL_CROSS_COMPILE_PREFIX to /bin/aarch64-linux-gnu- to make use of it (you can use shell command which -a aarch64-linux-gnu-gcc to get its real path).

The random reboot issue should be caused by overclock, which might be unstable on some devices with some types of battery (while others are fine, like my own Mi-4c). Try enable then disable "High performance mode" in "Settings > Battery > Battery saver and performance", and reboot your device to see if this issue is resolved. If you are using your own build, there might not be such options in Settings app. In this situation, run setprop persist.sys.cpu_overclock false in adb shell and reboot your device to disable overclock.

I will make a digest of our discussion and add it into #2, you can check it later this day.
 
Last edited:

d7791

New member
Dec 30, 2020
4
0
1
If you also installed gcc-aarch64 and gcc-arm on your computer, it's recommended to set TARGET_KERNEL_CROSS_COMPILE_PREFIX to /bin/aarch64-linux-gnu- to make use of it (you can use shell command which -a aarch64-linux-gnu-gcc to get its real path).

The random reboot issue should be caused by overclock, which might be unstable on some devices with some types of battery (while others are fine, like my own Mi-4c). Try enable then disable "High performance mode" in "Settings > Battery > Battery saver and performance", and reboot your device to see if this issue is resolved. If you are using your own build, there might not be such options in Settings app. In this situation, run setprop persist.sys.cpu_overclock false in adb shell and reboot your device to disable overclock.

I will make a digest of our discussion and add it into #2, you can check it later this day.
Yup, I confirm "setprop" solves the reboot issue (I performed cpu throttling over the night).
What is the difference between user and userdebug builds? What is the build which you make available to the the others in the first post? Do I need to apply more patches from you in order to get build like that?

After I "replicate" your build as much I as I can, I can start helping fixing any remaining issues.
 

WJXXBSH

Senior Member
Dec 22, 2018
86
56
18
Yup, I confirm "setprop" solves the reboot issue (I performed cpu throttling over the night).
What is the difference between user and userdebug builds? What is the build which you make available to the the others in the first post? Do I need to apply more patches from you in order to get build like that?

After I "replicate" your build as much I as I can, I can start helping fixing any remaining issues.
Usually, "user" build variant has less debug stuffs and more strict limits than "userdebug" variant. It also makes the system image smaller and may provide better performance (eg. proguard optimization is enabled for most apps). My ROMs on AFH or GitHub Releases are all "user" builds, but I also make "userdebug" builds for testing purpose (usually for myself).

To make "user" builds available, there are at least 3 patches needed:
  • patch/build/make/user-build-variant.patch
  • patch/system/core/allow-permissive.patch
  • patch/system/sepolicy/allow-permissive.patch
After applying these patches, there should be no build errors and the device should boot into desktop. Obviously, you cannot enable root access or use addon-su in "user" builds by default, but adb shell is still available. Some of my patches about "root-access" and "su" are designed to resolve these problems, but they are optional.

Unfortunately, due to some unknown issues (maybe some denied operations), the selinux status in my ROM cannot be "enforcing" in boot process (that's why you can find a androidboot.selinux=permissive in kernel cmdline). The "user" builds sets selinux to "enforcing" mode by default, which will result in a bootloop (that's why there are two necessary patches about "permissive"). I tried to collect the selinux audit logs before, but found nothing suspicious at last, then the selinux status in my ROMs has been "permissive" until now.
 
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone