- You need to have the Android SDK installed. The SDK contains the latest version of adb and fastboot, which you will need for flashing files and issuing commands.
- A MicroUSB cable to execute adb sideload, fastboot flash, and other commands.
- You also have to unlock your bootloader - a process that wipes your data.
- Enable Developer options by going to the Settings -> About screen and tapping Build number until the OS unlocks the hidden Developer options menu. Now go to Developer options and make sure you have USB debugging turned on. For security purposes, you can turn it off after we're done.
- To unlock the bootloader, if you haven't already done so:
- Reboot into the bootloader by issuing an adb reboot bootloader command on your computer or using the correct combination of buttons applicable to your device. Warning: This will wipe your data. Type in fastboot oem unlock on your computer. Agree to the unlock by selecting Yes on your device (VolUp, then Power).
- You have now unlocked your bootloader (and the data partition was wiped clean). Verify by rebooting to the bootloader again and looking at Lock State.
- Download the full factory image corresponding to your Nexus model (Nexus 4 is occam), which includes the full system, bootloader, recovery, kernel (boot.img), and radio (radio is not included for Wi-Fi-only variants).
- Unpack the tgz (tar/gz) archive into its own directory. You can use any tool that reads gz and tar, like 7-Zip.
- Proceed with this step if you want to keep your data intact. If you skip this step, your data will be wiped. With your favorite text editor, edit (be careful not to run it by accident instead of editing) flash-all.bat (if you're on Windows) or flash-all.sh (Mac, Linux) and remove "-w" from the fastboot update command. For example, if the line reads fastboot -w update image-razor-jss15j.zip, it should now read fastboot update image-razor-jss15j.zip. The -w option instructs fastboot to wipe data.
- Reboot into the bootloader and run the appropriate flash-all script.
Now you are done....
Note: The above procedure restored the factory recovery, so if you want a custom one, you can flash one now .For better security, you can relock the bootloader by issuing fastboot oem lock while booted to the bootloader. This will, however, mean that if you ever want to do anything that requires an unlocked bootloader, you will lose your data in the unlock process.
- Rooting your Nexus is very easy. It requires an unlocked bootloader and a custom recovery. I recommend using TWRP.
- Flash TWRP from here (Reboot into the bootloader as before and then fastboot flash recovery FILENAME.img).
- Reboot into recovery (adb reboot recovery).
- Flash SuperSU. To do that, download the zip, then put the recovery into adb sideload mode (in TWRP, it's under Advanced), and then do adb sideload FILENAME.zip.
You should be rooted.
Reboot, head to the Play Store, and update SuperSU.