Device Information
Warning: Xiaomi Mi 4c is no longer officially maintained. Developers interested in private builds or potentially reviving official support can use the build guide.
Installation
How to install LineageOS on Xiaomi Mi 4c
Build Guide
How to build LineageOS for Xiaomi Mi 4c
Update Guide
How to update LineageOS on Xiaomi Mi 4c
Special Boot Modes
- Recovery: Power off the device, press and hold Volume Up + Power. Keep holding both buttons until the "MI" logo appears, then release.
- Download: Power off the device, press and hold Volume Down + Power. Keep holding both buttons until "FASTBOOT" appears, then release.
Getting Help Online
You can find LineageOS assistance on our subreddit or in #LineageOS on freenode.
Xiaomi Mi 4c (libra) Specifications
- Released: September 2015
- System on Chip: Qualcomm MSM8992 Snapdragon 808
- RAM: 2/3 GB
- CPU: Hexa-core Cortex-A53 and Cortex-A57 4 x 1.44 GHz and 2 x 1.82 GHz
- Architecture: arm64
- GPU: Adreno 418
- Network:
- 2G bands: 850 900 1800 1900 GSM
- 3G bands: 850 900 1800 2100 HSDPA
- 4G bands: 1(2100),3(1800),7(2600),38(2600),39(1900),40(2300),41(2500) LTE
- Storage: 16/32 GB
- Display: 1920x1080 (441 PPI) IPS LCD
- Bluetooth: 4.1 with A2DP
- Wi-Fi: 802.11 a/b/g/n/ac, dual-band, Wi-Fi Direct, hotspot
- Sensors:
- A-GPS
- Accelerometer
- Dual SIM
- GLONASS
- GPS
- Gyroscope
- Hall effect sensor
- IR Blaster
- Light sensor
- Proximity sensor
- USB OTG
- Cameras: 2
- 13 MP, phase detection autofocus, dual LED (dual tone) flash
- 5 MP, no flash
- Dimensions: 138.1 mm (5.44 in) (height) x 69.6 mm (2.74 in) (width) x 7.8 mm (0.31 in) (depth)
- Battery: Non-removable Li-Ion 3080 mAh
Building for Libra
Note: This page was automatically generated for Xiaomi Mi 4c based on device information. Similar instructions can be found on this Wiki for each officially supported device.
Introduction
These instructions will help you get started with your Xiaomi Mi 4c, unlock the bootloader if necessary, then download the required tools and latest LineageOS source code (based on Google's Android operating system) for your device. Using these, you can build LineageOS and LineageOS recovery images from source code, then install them to your device.
It's difficult to say how much experience is required to follow these instructions. While this guide is certainly not extremely beginner-unfriendly, the steps don't require a PhD in software development either. Some readers can complete the steps without any trouble. Others might struggle with the most basic operations. Since people's experiences, backgrounds, and intuitions vary, it might be a good idea to read through to determine if you're comfortable or if you're in over your head.
Please remember that you undertake all risks in attempting this, but you'll be rewarded! Booting the new OS you baked at home is very satisfying :). Once you become an Android build ninja, you no longer need to wait for anyone's "nightly" builds. You'll have the skills to go from code to a complete operating system running on a device whenever and wherever you want. Wherever you go - perhaps you'll add a feature, fix a bug, add a translation, or use what you've learned to build a new application or port to a new device - or maybe you'll never build again - it's all up to you.
What You'll Need
- A Xiaomi Mi 4c
- A relatively modern 64-bit computer (Linux, macOS, or Windows) with a reasonable amount of RAM and about 100GB of available storage space (more if you enable `ccache` or build for multiple devices). Less RAM means longer build times (aim for 8GB or more). Using an SSD can significantly speed up build times compared to traditional hard drives.
- A USB cable compatible with Xiaomi Mi 4c
- A good internet connection and reliable power supply :)
- Familiarity with basic Android operations and terminology. This will help if you've installed custom ROMs on other devices and are familiar with recovery. Understanding some basic command line concepts is also useful, such as `cd`, which stands for "change directory", the concept of directory hierarchy, and how they are separated by / in Linux.
Tip: If you're not familiar with Linux, this is a great learning opportunity. It's free - just download and run a virtual machine (VM) like VirtualBox, then install a Linux distribution like Ubuntu (AOSP also checks Ubuntu). Any recent 64-bit version should work fine, but the latest Long Term Support (LTS) version is recommended. There are plenty of instructions on setting up VirtualBox to run Ubuntu, so we'll leave that to you. Let's get started!
Building LineageOS and LineageOS Recovery
Note: You only need to perform these steps once. If you have already set up your build environment and downloaded the source code, skip to Prepare device-specific code.
Install SDK
If you haven't installed `adb` and `fastboot` before, you can download them from Google. Extract it and run:
unzip platform-tools-latest-linux.zip -d ~
Now, you need to add `adb` and `fastboot` to your PATH. Open `~/.profile` and add the following:
# add Android SDK platform tools to path
if [ -d "$HOME/platform-tools" ] ; then
PATH="$HOME/platform-tools:$PATH"
fi
Then, run `source ~/.profile` to update your environment.
Install Build Packages
Building LineageOS requires several packages. You can use your distribution's package manager to install them.
Tip: A package manager in Linux is used to install or remove software (usually from the Internet) on your computer system. With Ubuntu, you can use the Ubuntu Software Center. Even better, you can use the `apt-get install` command directly in the terminal.
To build LineageOS, you need:
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
For Ubuntu versions earlier than 16.04 (xenial), replace:
- `libwxgtk3.0-dev` → `libwxgtk2.8-dev`
Java
Different versions of LineageOS require different JDK (Java Development Kit) versions.
- LineageOS 16.0: OpenJDK 1.9 (included by default)
- LineageOS 14.1-15.1: OpenJDK 1.8 (install `openjdk-8-jdk`)
- LineageOS 11.0-13.0: OpenJDK 1.7 (install `openjdk-7-jdk`)*
* OpenJDK 1.7 is not in the standard package repositories for Ubuntu 16.04 and later. Please see the Ask Ubuntu question "How to install openjdk 7 on Ubuntu 16.04 or higher?". Note that the suggestion to use the PPA openjdk-r is outdated (the PPA never updated openjdk-7-jdk packages and thus lacks security fixes); skip that answer even though it's the most popular.
Create Directories
You need to set up some directories in your build environment.
To create them:
mkdir -p ~/bin
mkdir -p ~/android/lineage
The `~/bin` directory will contain the git-repo tool (commonly called "repo"), and the `~/android/lineage` directory will contain the LineageOS source code.
Install the `repo` Command
Enter the following to download the `repo` binary and make it executable (runnable):
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
Add the `~/bin` Directory to Your Execution Path
In recent Ubuntu versions, `~/bin` should already be in your PATH. You can check this by opening `~/.profile` in a text editor and verifying the following code (add it if missing):
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
Then, run `source ~/.profile` to update your environment.
Initialize the LineageOS Source Repository
The following branches are available for building Xiaomi Mi 4c:
- CM-14.1
Enter the following to initialize the repository:
Note: Make sure you enter the branch you want to build here!
cd ~/android/lineage
repo init -u https://github.com/LineageOS/android.git -b cm-14.1
Download the Source Code
To start downloading the source code to your computer, type:
repo sync
The LineageOS manifest includes reasonable defaults for repo, and we strongly recommend using them (i.e., don't add any options for sync). For reference, our defaults are `-j 4` and `-c`. The `-j 4` part means there will be four concurrent threads/connections. If you encounter sync issues, you can lower this to `-j 3` or `-j 2`. On the other hand, `-c` will ask repo to bring in only the current branch and not all branches available on GitHub.
Note: This may take a while depending on your internet speed. Go grab a beer/coffee/tea/a nap in the meantime!
Tip: The `repo sync` command is used to update to the latest LineageOS and Google source code. Remember it, as you may want to run it every few days to keep the codebase fresh and up-to-date.
Prepare Device-Specific Code
After downloading the source code, make sure you're in the root directory of the source code (`cd ~/android/lineage`), then type:
source build/envsetup.sh
breakfast libra
This will download your device's specific configurations and kernel.
Device: https://github.com/LineageOS/android_device_xiaomi_libra
Kernel: https://github.com/LineageOS/android_kernel_xiaomi_msm8992
Important: Some devices need the vendor directory populated before breakfast will succeed. If you get an error about vendor makefiles here, skip to Extract proprietary blobs. The first part of breakfast should have already succeeded, so you can re-run `breakfast` after that's done.
Extract Proprietary Blobs
Note: This step requires the device to already be running the latest LineageOS, depending on the branch you're building for. If you don't have access to such a device, see Extracting proprietary blobs from an installable zip file.
Now make sure your Mi 4c is connected to your computer via USB cable, ADB and root are enabled, and you're in the ~/android/lineage/device/xiaomi/libra folder. Then run the `extract-files.sh` script:
./extract-files.sh
The blobs should be pulled into the `~/android/lineage/vendor/xiaomi` folder. If you see "command not found" errors, `adb` might need to be placed in `~/bin`.
Enable Cache to Speed Up Builds
To speed up subsequent build runs with `ccache`:
export USE_CCACHE=1
And add that line to your `~/.bashrc` file. Then, specify how much disk space you want `ccache` to use by typing:
ccache -M 50G
Where `50G` corresponds to 50GB of cache. This needs to be run once. Anywhere from 25GB to 100GB can significantly improve build speeds (for example, a typical 1-hour build time can be reduced to 20 minutes). If you're only building for one device, 25GB-50GB is fine. If you plan to build for several devices that don't share the same kernel source, aim for 75GB-100GB. This space will be permanently taken from your drive, so take that into account.
You can also enable optional `ccache` compression. While this may lead to a slight performance hit, it will allow more files to fit in the cache. To enable it, run:
export CCACHE_COMPRESS=1
Or add that line to your `~/.bashrc` file.
Note: If compression is enabled, the `ccache` size can be lower (for one device, aim for around 20GB).
Configure Jack
Jack is currently the Java toolchain used for building LineageOS 14.1 and 15.1. It's known to run out of memory if not configured correctly - a simple fix is to run this command:
export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4G"
Adding this command to your `~/.bashrc` file will automatically configure Jack to allocate enough memory (4GB in this case).
Start Building
It's time to start building! Now, type:
croot
brunch libra
The build should start.
Tip: Want to know how to sign your own builds? Check out Signing Builds.
Install the Build
Assuming the build completed without errors (which will be obvious when it does), in the terminal window where the build was running, type:
cd $OUT
There you can find all the created files. The two more interesting files are:
recovery.img, this is the LineageOS recovery image.lineage-14.1-20190717-UNOFFICIAL-libra.zip, this is the LineageOS installer package.
Success! What's Next?
You did it! Welcome to the elite club of self-builders. You built your operating system from scratch. You are the master/mistress of your domain... hopefully you've learned something along the way and had some fun too.
Getting Help
- #LineageOS-dev - A helpful real-time chat room (or "channel") on the Freenode IRC network.
Extracting Proprietary Blobs from LineageOS Zip Files
Introduction
Proprietary blobs can be extracted from a device already running LineageOS or from a LineageOS installable zip. In this guide, we'll describe the steps needed to extract proprietary files from an installable zip.
Before starting, you need to know the difference between a block-based OTA and a file-based OTA. In a file-based OTA, the contents of the system partition are available in a folder named `system` within the zip. In a block-based OTA, the contents of the system partition are stored as binary data within a file. If your zip doesn't have a `system` folder or an almost empty `system` folder, and has a file named `system.transfer.list` in its root, then you have a block-based OTA. In that case, skip to Extracting proprietary blobs from a block-based OTA. If you have the full contents of the system partition in a `system` folder without a `system.transfer.list`, then you have a file-based OTA. See Extracting proprietary blobs from a file-based OTA.
Extracting Proprietary Blobs from a Block-Based OTA
Create a temporary directory and move into it:
mkdir ~/android/system_dump/
cd ~/android/system_dump/
Extract `system.transfer.list` and `system.new.dat.br` or `system.new.dat` from the LineageOS installable zip:
unzip path/to/lineage-*.zip system.transfer.list system.new.dat*
Where `path/to/` is the path to the installable zip.
If there's a `system.new.dat.br` (brotli archive), you first need to decompress it using the `brotli` utility:
sudo apt-get install brotli
brotli --decompress --input system.new.dat.br --output system.new.dat
Now you need to get a copy of `sdat2img`. This script can convert block-based OTA contents to a dump that can be mounted. `sdat2img` can be found in the following git repository, which you can clone using:
git clone https://github.com/xpirt/sdat2img
Once you have `sdat2img`, use it to extract the system image:
python sdat2img/sdat2img.py system.transfer.list system.new.dat system.img
You should now have a file named `system.img` that can be mounted like this:
mkdir system/
sudo mount system.img system/
After mounting the image, navigate to the root directory of the device source and run `extract-files.sh` as follows:
./extract-files.sh ~/android/system_dump/
This will tell `extract-files.sh` to get files from the mounted system dump instead of from a connected device.
After all proprietary files have been extracted, unmount the system dump and remove no longer needed files:
sudo umount ~/android/system_dump/system
rm -rf ~/android/system_dump/
Extracting Proprietary Blobs from a File-Based OTA
Create a temporary directory to extract the contents of the zip and move into it:
mkdir ~/android/system_dump/
cd ~/android/system_dump/
Extract the `system` folder from the zip:
unzip path/to/lineage-*.zip system/*
Where `path/to/` is the path to the installable zip.
After extracting the `system` folder, navigate to the root directory of the device source, then run `extract-files.sh` as follows:
./extract-files.sh ~/android/system_dump/
This will tell `extract-files.sh` to get files from the extracted system dump instead of from a connected device.
Once all proprietary files have been extracted, you can remove the files extracted from the zip:
rm -rf ~/android/system_dump/
Signing Builds
Generate Keys
Note: You only need to run these once. If you re-run these, you'll need to migrate between builds - see Change Keys
Run these commands from the root of the Android tree, changing the `subject` line to reflect your information:
subject='/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
mkdir ~/.android-certs
for x in releasekey platform shared media testkey; do \
./development/tools/make_key ~/.android-certs/$x "$subject"; \
done
You should keep these keys secure and save the passwords in a safe place.
Generate the Installer Package
Tip: If you want to preserve data from an unmodified Lineage build, see Change Keys.
Generate and Sign Target Files
Following the device build instructions instead of running `brunch
breakfast <codename>
mka target-files-package otatools
Sit back and wait - this may take a while depending on your computer specs. When finished, you just need to sign all the APKs:
croot
./build/tools/releasetools/sign_target_files_apks -o -d ~/.android-certs \
$OUT/obj/PACKAGING/target_files_intermediates/*-target_files-*.zip \
signed-target_files.zip
Generate the Installer Package
Now, to generate the installable zip, run:
./build/tools/releasetools/ota_from_target_files -k ~/.android-certs/releasekey \
--block --backup=true \
signed-target_files.zip \
signed-ota_update.zip
Then, install the zip in recovery as usual.
Change Keys
Using a Migration Build
Warning: Using these patches to build is insecure - it will reset keys on all packages on every boot. Install them as little as possible.
You can set up your own migration build by running the following commands:
LineageOS 16.0:
repopick 239520
LineageOS 15.1:
repopick -f 192655 -P vendor/lineage
repopick -f 192656 -P frameworks/base
LineageOS 14.1:
repopick 156047 162144
Then, follow the instructions to generate the installer package.
Going Back
After installing the migration build, you can switch back to building normal builds:
LineageOS 16.0:
cd frameworks/base
git reset --hard github/lineage-16.0
LineageOS 15.1:
cd vendor/lineage
git reset --hard github/lineage-15.1
croot
cd frameworks/base
git reset --hard github/lineage-15.1
LineageOS 14.1:
cd vendor/cm
git reset --hard github/cm-14.1
croot
cd frameworks/base
git reset --hard github/cm-14.1
Using a Script
Before installing a build with new keys, you can also use a script designed to run once or a small flashable zip. The script can be found below `./lineage/scripts/key-migration/script.sh`
You can also make the script into a zip by inserting it into a zip similar to this. This zip file contains `META-INF/com/google/android/update-binary` which has some additional content for printing status messages to recovery.
Test Keys to Official, and Vice Versa
If you're moving from a build with test keys (e.g., an "unsigned" unofficial build) to an official LineageOS build, you can push the script to your device and run it from Android:
adb root # This requires an userdebug/eng build and ADB root access to be enabled
adb shell stop
adb push ./lineage/scripts/key-migration/migration.sh /data/local/tmp/migration.sh
adb shell chmod +x /data/local/tmp/migration.sh
adb shell sh /data/local/tmp/migration.sh official
adb reboot recovery
# Now install the official LineageOS install zip
Or run it from recovery:
# Ensure both /data and /system are mounted, then continue
adb push ./lineage/scripts/key-migration/migration.sh /data/local/tmp/migration.sh
adb shell chmod +x /data/local/tmp/migration.sh
adb shell /data/local/tmp/migration.sh official
If you want to move from an official version to your own "unsigned" version, you can run the script in the same way, but using the parameter "unofficial" instead of "official".
Test Keys to Your Own Release Keys, and Vice Versa
If you want to move from test keys to your own signed version, you can add your own keys to the script. First, export your keys in the required format by running the script `./lineage/scripts/key-migration/export-keys.sh`.
Note: You may need to modify this script to change the location of the certificate directory if you don't use the default one.
This will print the keys and certificates to the terminal in the required format. Next, edit the script to use your keys. You need to comment out (by prefixing a `#`), or remove, the existing definitions for the "release" key and certificate. Now, copy and paste the output from above into the script where the existing lines were. Make sure to keep the "test" key and certificate definitions unchanged.
Your script is ready! Push it to your device and run it in the same way as above, then install your own signed zip. If you need to run it in reverse, just use the "unofficial" parameter instead of "official", and your keys will be replaced with the official ones.
All Content
- Build guides
- Contributing
- Contributing to the wiki
- Extracting proprietary blobs
- Frequently Asked Questions
- Google apps
- How-to...
- Information for Lineage Developers
- Install guides
- LineageOS contributors
- LineageSDK
- Requesting LineageOS for your device
- Signing Builds
- Submitting a port
- Upgrade guides
- Using ADB and fastboot
- Verifying Build Authenticity
How-to...
- ...capture logs
- ...import the sources to Android Studio/IntelliJ
- ...submit a bug report
- ...submit a patch
- ...translate
- ...use Gerrit