HTC One M9 to Lineage OS 14.1 (Android 7.1.2)
Image Credits: HTC Corporation, Lineage OS
I have a HTC One M9 here at the office we have been using for Android development. It was a trade for a bunch of my older computer hardware, otherwise I probably would have bought a Nexus. It is a great phone, but I have never been a fan of HTC Sense. Additionaly, having a custom UI/UX on the phone makes it harder to judge if an app's appearance is consistant with the current Android UI/UX.
Being a tinkerer at heart, I decided to flash a custom ROM on the phone. In the past, I had used CyanogenMod flash my Samsung Galaxy SII. Unfortunately, it appears to no longer exist. Its successor, Lineage OS, does appear to be in active development.
Unlock the Device
This was a locked phone, so the first step was to unlock the bootloader. HTC allows this via the https://www.htcdev.com/ website. After creating an account and selecting my device, I was given a quick set of instructions on unlocking the device. Here is a summary (this is for Linux, Mac/Windows will be similar):
- Install fastboot if necessary (or HTC provides a binary):
sudo apt-get install android-tools-fastboot
- On the phone, go to Setting -> About -> Software Information -> Build number
- Repeatedly tap Build number to put the phone in Developer Mode
- Go back to Settings, then to Developer options and enable OEM unlocking. Some sources mention going to Setting -> Power and disabling Fastboot mode.
- Power off the device
- Power on the device into Download mode by holding Power + Volume down when booting. Older version might call this Fastboot mode (unrelated to above).
- Plug phone into PC, you can check if it is connected by typing -- Notice this has to be run as root; I was tripped up by this for an hour. You will just recieve a message "Wating for device..." if this is run as a non-root user.
sudo fastboot devices
- Grab the identifier token
sudo fastboot oem get_identifier_token
- Paste this in the form at https://www.htcdev.com/
- You will receive a file Unlock_code.bin, download it and apply it to the device while it is still in Download mode
sudo fastboot flash unlocktoken Unlock_code.bin
- There will be some promps on the phone. Follow them through.
The phone should now be unlocked. In Download mode, the it should say something like *** UNLOCKED *** at the top.
Install custom recovery image
The next step is to install a custom recovery, TWRP, on the phone. Go to https://twrp.me/devices/htconem9.html and download the appropriate *.img file. While still in download mode, flash it onto the phone:
sudo fastboot flash recovery twrp.img
Reboot the device.
Finally, we can flash the Lineage OS package.
- Once you are back in Android, allow file transfers.
- Go to https://download.lineageos.org/himaul and download LineageOS.
- Copy this file to the Internal Storage of the phone. (note: if you want Google Apps, jump ahead to that section, download, and copy that package to the Internal storage as well)
- Reboot the device back into Download mode.
Now we need to get into our custom recovery. Select Reboot to Bootloader then when on a white screen, Boot to Recovery Mode. This will open TWRP. Swip to allow modification.
First, we need to Factory reset the phone and wipe the Cache.
- Select Wipe
- Select Advanced Wipe
- Check cache, System, and Data
- Swipe to Wipe
Go back to the Main menu and install the *.zip
- Select Install
- Choose the *.zip
- Swith the confirm Flash
After complete, you can choose to install the TWRP app.
Do not reboot into LineageOS yet if you want Google Apps. If you install Google Apps after booting into LineageOS, expect crashes. If you miss this note, you will need redo the wipe procedure, then install).
Install the Google Apps package (optional, but probably not in reality)
Due to licensing restriction, Google Apps (including the play store) cannot be included directly with LineageOS. These havce to be installed manually. Unless you intend to solely side load apps or use an alternate app store (such as Amazon App store). We highly recommend you download the Google Play Store.
- Go to Open GApps http://opengapps.org/?api=7.1&variant=nano and download the preferred variant of the Google Apps package. I did ARM64, Android 7.1, and nano.
- Plug the phone into the computer and allow file transfers
- Copy the *.zip to the Internal storage
- Boot into Download mode, then follow the steps above to get into our custom recovery
- Click install
- Choose the Google Apps *.zip package
- Swipe to confirm Flash
Reboot and enjoy!