Wednesday, April 22, 2015

OnePlus and CyanogenMod meets Android 5.1




This is a terse but factual account of how to install and CyanogenMod based Android 5.1 onto you OnePlus phone


Audience

OnePlus smartphone owners have been waiting forever for CyanogenMod OS based on Android 5.0 but recently the first builds of CyanogenMod (CM) 12.1 based on Android 5.1 have appeared.  In this tutorial we will install (not upgrade) to CM 12.1 


Disclaimers
The following procedure if mis stepped can render your phone dead as a dodo and then you are a little screwed.  I accidentally have two working phones  (see Two Phone Strategy) and so this procedure is being operated on my secondary phone, so should it go wrong I won't be in a big panic and can take the time to fix it.  

Data Deletion

This procedure deletes all data and applications on your phone.  Whilst they will be re-installed (because automatic backups of the existing phone are set on) note that you need to enter all userids and passwords for each application again as necessary (example DropBox).

Also, note for me that it's the other Primary phone (my Nexus 5) that has my Google Authenticator and other 2 step Authentication programs on.  So this leaves this OnePlus phone a clean and isolated upgrade.



Install an Android SDK onto a controlling PC




Download the Slim Android SDK  (Software Development Toolkit) and unpack the zip file.  The files should be as above.



For Marcus, as in a previous Android tutorial, I needed to use a Windows 7 , 32bit system.  None of my Windows 64 bit 8, 2012 installations (on the same hardware, physical not virtual) worked with this software. Bizarre.



Start Phone in Fastboot mode

I powered off the Oneplus phone then powered on and held volume up button.  Phone displays /Fastboot Mode/ words on screen.


Unpack SDK and Test it




Connect your OnePlus in /fastboot mode/ and fastboot devices must return something, after which you can unlock.


fastboot devices
fastboot oem unlock

If devices does not show anything you need to check the cable, try with alternative drivers here or here  You can't get anywhere till a connected phone over USB responds to fastboot.  So if you are here and nothing works you need to Google.




Install TWRP binary


I downloaded latest TWRP (Team Win Recovery Program) from here  leading to a 2.8.6.0 file from  http://dl.twrp.me/bacon/twrp-2.8.6.0-bacon.img


As you know Bacon is the codename for the OnePlus phone.

With this file in the same directory as fastboot.exe and the OnePlus still connected and in Fastboot mode, install the latest TWRP program



fastboot flash recovery twrp-2.8.6.0-bacon.img

I explained more about TWRP in my 2 phone post but essentially this is a superior Recovery program that allows you to perform multiple diagnostic operations, or backups or installs.



Making a Backup

After TWRP is installed you can easily make a backup of your existing installation, and then transfer this to your PC afterwards for real protection  (should the phone get fully wiped)

Right now your phone is still connected to a Android SDK installed computer via the USB cable.  So we disconnect the phone, personally I then plug it into a mains adapter.  Power off, then start TWRP by Power On + Volume Down button







Select Backup




Connect to a PC and save all the Backup files with Copy / Paste.  For the impatient, know that the whole process takes <5 minutes.




Now we are ready to install the new OS properly:
Prepare Sources


Download 3 necessary files:


Latest Bacon Firmware


Latest 12.1 Build


Latest Google Apps  (I choose stock)




For me this looked like above



Transfer OS to Phone Disk


Now with TWRP booted, you need to mount some partitions and transfer these files downloaded to PC to the phone and then install them.  Perversely I could not do this on the Windows 7.32 machine I used to fastboot unlock the phone with since it could not see the Phones 'disk' as a drive no matter what drivers I installed. 


So, what I did was boot the phone into TWRP, then plug that into different computers until one of them could see the TWRP booted filesystem I needed ...




Initially phone is off, then powered on and holding volume down button. Should boot into TWRP.  If it boots to Android then power down and try again!





 Mount option and select System and Data and Cache

Plug in the phone and create a directory called ROMs and put into it the 3 files you previously downloaded.




Wipe Existing Installation


In the Wipe option choose Dalvik, System, Data, Cache and wipe it.




Install new CM12.1 i.e. Android 5.1 OS






Now in the install step select the firmware, cm-12.1, and finally the pa_gapps file in that order and install.

After completion (< 60 seconds) reboot!



It is rebooting and I'm sorry about the very mucky screen!


Basically at this point we are done, for completeness I'll paste in the remaining screens



 Rule Britannia and install UK English.









 Add back my gmail account



 Restore backup and all applications












At this point it has to download all your applications from the Play store and install them.  During this part apps icons with circles around them as shown are being installed.






Quite a few cups of coffee later and all is installed and working.   Voila.



Further updates from the Google Play store are then made to really complete everything.


All I had to do now was

- Fiddle around and reinstate my favourite settings (clock position, display timeout, lockscreen etc)
- Start some applications that need userid and Passwords e.g. Withings fitness, Runkeeper, DropBox
- Make sure DropBox and Google Drive are doing automatic uploads and backups
- etcetera

Total time of whole operation is < 1 hour end to end, once your are practised. 

I hope this works for you and that you can now enjoy Android 5.1 based CyanogenMod.



Notes:


Bootloop

If whilst installing/ upgrading the phone gets to the end of the process, prints an error then reboots and tries again it might get stuck in an infinite /bootloop/.

To solve  First: 
Read this article

Essentially what you would need to do is


- Try wiping Dalvik cache

- Install a different OS build, at worst the one that you had previously installed  (i.e. a backout)

Note that right now I  can't seem to upgrade from any CM12 (Android 5.0) or CM12.1 (Android 5.1) base to a later CM 12.1.  I always got a bootloop.  So for example, right now to change to a later daily build I could not upgrade (dirty flash) but only reinstall (clean flash) everything.  So I have not shown the simpler upgrade procedure in this article since it does not work! (just yet)







Links

Latest Bacon Firmware
Latest 12.1 Build
Latest Google Apps