Rooting the Nexus 7

Nexus-7-Bootloader

The Nexus 7 is an excellent device. It is, in my opinion, the best value in the tablet world. Great specs, bleeding-edge Android releases, and low cost. You really can’t beat it. As I worked on rooting my Nexus 7 (2013 edition), I realized it would make for a good tutorial. The process is pretty simple, once you know what you’re doing, but getting there can take a bit of work. In this article, I’ll lay out the steps I took to get my Nexus rooted, hopefully making it easier for others to figure out in the future. I’ve used these directions on both the 2012 and 2013 editions of the Nexus 7, and I imagine they would work just as well on any Nexus device. Note that these directions are designed for Windows 7 users. Much of the directions will apply to other operating systems, but some adaptation may be necessary.

Your first question may be, “What’s rooting?” Per Wikipedia:

Android rooting is the process of allowing users of smartphones, tablets, and other devices running the Android mobile operating system to attain privileged control (known as “root access“) within Android’s subsystem.

Rooting is often performed with the goal of overcoming limitations that carriers and hardware manufacturers put on some devices, resulting in the ability to alter or replace system applications and settings, run specialized apps that require administrator-level permissions, or perform other operations that are otherwise inaccessible to a normal Android user. On Android, rooting can also facilitate the complete removal and replacement of the device’s operating system, usually with a more recent release of its current operating system.

So, why did I want to root my tablet? One reason: backups. Android is sorely missing a proper backup system. The built-in backup system manages to backup a few system settings, a list of apps you have installed, and if you’re using an online storage system of some sort, photos. That’s it. After my Nexus 7 mysteriously reset itself, losing the majority of settings and apps in the process, I decided it was time to get a real backup routine running.

Unfortunately, backup programs require root access. Using that access, the programs are able to backup every aspect of your device. Applications, applications settings, system settings, files, etc. Nicely, the Nexus devices make it especially easy to gain root access. You don’t need to “hack” the phone to unlock it. You simply need the right software, and need to know the right commands. Going forward, I’ll be rooting every Android device I own.

Note: rooting your device will completely reset your device. Most of your settings will be lost. This is non-reversible! The files on the internal SD card will be safe, though.

Where to Begin?

Having never delved into the world of rooting (also known as jailbreaking in some circles), I really didn’t know where to start. In my search, I browsed and read through a number of articles and tutorials. Everything I now know about rooting, I know from having read these pages:

http://lifehacker.com/5784857/how-to-set-up-a-fully-automated-app-and-settings-backup-on-android
http://forum.xda-developers.com/showthread.php?t=1118120
http://androidforums.com/evo-4g-all-things-root/129648-quick-intro-rooting-those-new-rooting.html
http://www.theandroidsoul.com/nexus-7-2013-bootloader-unlocking-guide/
http://forum.xda-developers.com/forumdisplay.php?f=2407

There’s some great info to be found in the links above, so I highly recommend giving them a read. Mind you, it shouldn’t be necessary after having read this article, but there’s nothing wrong with having a bit of extra information.

As I previously mentioned, the Nexus devices are pretty easy to unlock. In the past, it took special hacks and exploits to unlock a device. More and more devices now allow you to unlock them with a few simple commands, and the Nexus devices were one of the first to move in this direction.

I found these directions to be a great start: http://forum.xda-developers.com/showthread.php?t=2382051&page=1. They left out a good amount of the process, though, so I’ll try to go into more detail in this article.

Wiping the Device

The first thing we’re going to do is completely reset the device. This may not be necessary, but I believe it is best to start from a completely clean slate. Everything will be wiped as part of the unlocking process, no matter what you do, so it doesn’t hurt to do it yourself.

Source: https://support.google.com/nexus/answer/2668187?hl=en

  1. If your tablet is on, power it off.
  2. Hold down the Volume Down button, then press and hold the Power button until the device powers on. Continue to hold both buttons. You should see the word Start with an arrow drawn around it.
  3. Press the Volume Down button twice to select Recovery mode.
  4. Press the Power button to restart into Recovery mode. You will see an image of an Android robot with a red exclamation mark.
  5. While holding down the Power button, press the Volume Up button. The Recovery menu will now come up.
  6. Use the volume keys to scroll to “wipe cache partition” and press the Power button to select it.
  7. Next, select the “wipe data/factory reset” option. It will ask you to confirm. Scroll to “Yes — delete all user data” and press the Power button to make that selection.
  8. Finally, select “reboot system now”.
  9. After rebooting, your device will behave like a new, factory-fresh device. Go ahead and enter your WiFi info and log into your Google acount.
  10. As soon as the device gets to the “desktop”, open Play Store and stop all downloads.
  11. While in the Play Store, go into Settings and disable Auto-update Apps. There’s no need to install or update any applications at this point.

Installing the Java JDK

In order to interact with an Android device via your computer, you’ll need to install the Android SDK (Software Development Kit), and in order to install the SDK, you’ll need to install the Java JDK (Java Development Kit).

I found this post helpful when working out the JDK and SDK stuff: http://forum.xda-developers.com/showthread.php?t=1830108.

  1. Download the Java JDK here: http://www.oracle.com/technetwork/java/javase/downloads/index.html. Look for something like “Java Platform (JDK) 7u45”. Note that you’ll want to download whatever version is current at the time you are reading this. Click the download link, and it should take you to a page where you can choose from a long list of installers. Choose the version that is appropriate for your OS.
  2. If you’re running a 64-bit OS, then after the installation you’ll need to setup some environment variables. Go to Control Panel –> System –> Advanced System Settings (in the left-hand pane) –> Advanced tab –> Environment Variables button.
    1. Create a new variable named “JAVA_HOME”.
    2. Set the value to “%ProgramFiles%\Java\jdk1.7.0_45”, adjusting the version number to whatever version you’ve installed. Browse to the installation directory to verify which version you’re running. You’ll need to update this variable whenever you update the JDK in the future. Try to update the JDK whenever you update the normal Java installation.
    3. Next, edit the Path variable, adding “;%JAVA_HOME%\bin” to the end. Be careful with the Path variable, as you don’t want to remove any other directories in this variable. The Path variable tells the OS to look here when you go to run applications via the Command window. This saves you from having to enter the full path of an application.
  3. Reboot your computer.

Installing the Android SDK

The Android SDK contains the tools necessary to develop applications for the Android OS. It also contains various tools for connecting to and interacting with Android-based devices. You’ll need to install the SDK to continue along the path to full root access on your Android device.

  1. Download the Android SDK here: http://developer.android.com/sdk/index.html.
  2. For rooting purposes, only the SDK tools are necessary. Download the version appropriate to your OS. Being on Windows, I chose to download the Windows installer: installer_r22.3-windows.exe. You could download the .zip version and run the tools as needed, but that tends to be a bit of a pain.
  3. Run the installer. If all went well with the Java JDK installation, it should detect Java.
  4. I chose to install the SDK for anyone’s use, as that results in the files ending up in a more standardized location. Choose to install the files as you see fit.
  5. After installation completes, launch the Android SDK Manager. You may get an option to launch it as part of the installation. Choose not to do so. This tool is used to download and install the various Android SDK files. You can launch the tool at any point to check for and install updates, new API levels, newly released documentation, etc.
  6. Find the Android SDK Manager in your Start Menu, right-click on it, and choose “Run as administrator”. This is essential for the tool to properly install its components.
  7. Select “Android SDK Tools”, “Android SDK Platform-tools”, and “Google USB Driver”, then click “Install packages”. You’ll find the USB driver under the Extras section near the bottom of the list. Your selections may look different than that shown in the picture below, as you’ll be newly installing the tools.

    A look at the Android SDK Manager screen when updates are available.

    A look at the Android SDK Manager screen when updates are available.

  8. Click “Accept License” in the lower-right portion of the screen, then click Install.

    Android SDK Manager License Acceptance Screen

    Android SDK Manager License Acceptance Screen

  9. You’ll be returned to the SDK Manager’s main screen, where you can watch the progress as the files you selected are installed. When done, close the SDK Manager. The platform tools and USB drivers will now be located in the SDK install location.

    Android SDK Manager Installation Progress

    Android SDK Manager Installation Progress

Installing the USB Drivers

The previous steps simply placed the USB drivers on your system; it didn’t actually install them. So, the next step is to get them installed.

If you hadn’t already installed the drivers using the SDK Manager, you could find them here: http://developer.android.com/sdk/win-usb.html. Google’s instructions for installing the USB drivers are available here: http://developer.android.com/tools/extras/oem-usb.html#InstallingDriver. Peruse them, if you like. I’ll be walking you through similar steps below.

Before your computer can interface with the Nexus, USB debugging has to be enabled. To do so, complete the following steps:

  1. On the Nexus, go to Settings, and then About tablet.
  2. Now, click on the Build number near the bottom of the listing seven times. After the seventh click, the device’s developer options will be unlocked.
  3. Go back to Settings, then into Developer options.
  4. Enable USB debugging by ensuring that there is a check next to that option. Click OK when the confirmation comes up.
  5. When you first plug the device into your computer, you will get a message regarding the computer’s RSA key fingerprint. Make sure to click “OK” to allow your computer to interact with the device. You can choose the “Always allow from this computer” option, if you don’t want to deal with this message in the future.

First, install the Android Composite ADB Interface driver:

  1. Plug the Nexus into a USB port on your computer. You’ll probably get a message about a failed driver installation. If so, just ignore it. If AutoPlay launches, go ahead and close it. If your device does not appear to connect to your computer, at all, then a bad USB cable is the most likely culprit. Not all cables are created equal. Make sure you are using a cable that supports data transfer, in addition to charging capability. The cable that came with the device is usually a good choice.
  2. Go the Control Panel, then Device Manager.
  3. Look for the Nexus 7 in the list. You should find it under “Other Devices”.
  4. Right-click on the the Nexus and choose “Update Driver Software…”
  5. Click on “Browse my computer for driver software”, then “Let me pick from a list of device drivers on my computer”.Google-USB-Driver-0001-highlightedGoogle-USB-Driver-0002-highlighted
  6. Click “Show All Devices”, then click “Next.”
  7. Click “Have Disk…”, click “Browse”, then browse to the location where you installed the SDK earlier.
  8. Drill down to the “usb_driver” folder and select “android_winusb.inf”. On my system, the file was located under this path: C:\Program Files (x86)\Android\android-sdk\extras\google\usb_driver\.
  9. Select “Android composite ADB Interface”, then click Next. If you’re asked if you want to install the software, click “Install”.Google-USB-Driver-0003
  10. When the driver installation has completed, you’ll see the screen below. Click “Close”, and you should now see “Android Composite ADB Interface” listed under “Android Device” in the Device Manager.Google-USB-Driver-0004Google-USB-Driver-0005

To test out the newly installed USB drivers, open a Command prompt and navigate to the location where the SDK is installed, then into the platform-tools directory. In my case, the correct path is C:\Program Files (x86)\Android\android-sdk\platform-tools\. Type “adb devices”, and you should see your device listed.

Next, install the Android Bootloader Interface driver:

  1. Make sure USB debugging is still enabled, and leave the USB cable connected to your computer.
  2. Power off the Nexus.
  3. Power it back on by holding Volume Down + Power at the same time. Some directions I’ve seen say to hold Volume Down + Up, but that will just get you into USB mode.
  4. If you’ve pressed the right buttons, you should see the Android robot in the middle of the screen, with a large banner up top that says “Restart bootloader”, “Recover Mode”, “Power Off”, or “Start”.
  5. If “QHUSB_DLOAD” appears in the Device Manager on your computer, you’re in the wrong mode. Power off the Nexus and try again, starting from step 3 above.
  6. If you’re in the correct mode, find the newly listed device in Device Manager, and install the bootloader drivers. Follow the same steps as with the ADB driver, but this time select the “Android Bootloader Interface” driver.

Unlocking the Bootloader

Before we can root the Nexus, we need to unlock the device’s bootloader. The bootloader is similar to the bios on a typical computer. It tells the device what operating system to load. For a long time, bootloaders have been tightly locked down, requiring elaborate hacks to unlock them. Lately, manufacturers have been shipping their devices with less-restricted bootloaders. They’re still shipped in locked mode, but the lock is easily removed via a few simple commands. Here’s a good article regarding bootloaders, for those interested in a bit more info: http://www.addictivetips.com/mobile/what-is-bootloader-and-how-to-unlock-bootloader-on-android-phones-complete-guide/.

First, we need to boot into the bootloader. You have two options for doing so.

  1. Power off the Nexus, then turn it back on while holding both the Volume Down and Power buttons.
  2. This way is a bit easier (though it may not seem like it at first), much quicker, and gives you a chance to try out the drivers we just installed.
    1. With the device fully booted, plug it into a USB port on your computer.
    2. You may get a message regarding the computer’s RSA key fingerprint. Make sure to click “OK” to allow your computer to interact with the device. You can choose the “Always allow from this computer” option, if you don’t want to deal with this message in the future (at least until the device has been reset).
    3. Open a Command window.
    4. Navigate to where the Android SDK is installed (C:\Program Files (x86)\Android\android-sdk\platform-tools\ on my system).
    5. Type “adb reboot bootloader” (without the quotes). You just sent a command directly to the device, telling it to reboot into the bootloader.

You should now see the Android robot in the middle of the screen (in “Operation” mode). Look at the listing of specs near the bottom of the screen. It should say “LOCK STATE – LOCKED”. Your goal is to change that to “UNLOCKED”.

  1. In the Command window you used to reboot the device (if you didn’t use that method to reboot, follow steps 2A – 2D above), type “fastboot oem unlock” (without quotes).
  2. Read the warning message on your device, use the volume keys to select the option to proceed with the unlock, then press the Power button.
  3. Note: If you did not previously wipe your device, then this will erase all data on your device. There is no going back. Data on the internal SD card will remain, though.
  4. After a few seconds, the device will return to the bootloader screen. It should now say “LOCK STATE – UNLOCKED” near the bottom.
  5. If Start isn’t selected near the top of the screen, press Volume Up or Down to select it, then press Power to start the device.

Installing a Custom Recovery Interface

The next step is to install a custom recovery interface. We’ll be installing TWRP. The recovery interface, as shipped with the device, is very basic. It is used to reset the device when it will no longer boot, and not much more. The new recovery interface we’ll be installing performs many more functions, and will allow us to easily root the device.

Since the system was just reset, we need to re-enable USB debugging.

  1. After the device starts up, go through the initial setup as you normally would.
  2. As soon as the device gets to the “desktop”, open Play Store and stop all downloads.
  3. While in the Play Store, go into Settings and disable Auto-update Apps. There’s no need to install or update any applications at this point.
  4. Go into the device’s Settings, and then About tablet.
  5. Now, click on the Build number near the bottom of the listing seven times. After the seventh click, the device’s developer options will be unlocked.
  6. Go back to Settings, then into Developer options.
  7. Enable USB debugging by ensuring that there is a check next to that option. Click OK when the confirmation comes up.
  8. You will most likely see a message regarding the computer’s RSA key fingerprint. Make sure to click “OK” to allow your computer to interact with the device. You can choose the “Always allow from this computer” option, if you don’t want to deal with this message in the future.

Now, we’ll download a couple of apps for the Nexus.

  1. First, download TWRP from http://www.teamw.in/twrp_view_all_devices.
    1. Find your device in the list. For the Nexus 7, you’d want Nexus 7 (this is for the 2012 version), Nexus 7 3G, Nexus 7 2013 LTE, or Nexus 7 2013 Wi-Fi Only.
    2. Click the link for your device, then click the download link on the next page.
    3. On the next page, download the latest version you see listed. It should be at the bottom of the list, and be named something like “openrecovery-twrp-2.6.3.1-grouper.img”.
    4. Copy your newly downloaded file to your platform tools directory (something like C:\Program Files (x86)\Android\android-sdk\platform-tools\), and rename it to “recovery-twrp.img”. We’re renaming it just to make it easier to type later on. Depending upon your system settings, you may have to provide administrator privileges to copy and rename the file.
  2. Now, download SuperSU from http://download.chainfire.eu/345/SuperSU/. Download the .zip file on the home page. This is what will give other applications root access to your device.
  3. If your device isn’t already connected to your computer, connect it now, and make sure it is on.
  4. Open the device in the listing of drives on your computer, then browse to Internal Storage.
  5. Copy the SuperSu .zip you downloaded earlier to the device’s Internal Storage. Leave it right there in the root directory.

Now,  we’ll boot into the bootloader and install TWRP.

  1. Open a Command window.
  2. Navigate to where the Android SDK is installed (C:\Program Files (x86)\Android\android-sdk\platform-tools\ on my system).
  3. Type “adb reboot bootloader” (without the quotes).
  4. Once the device has rebooted, and the bootloader is up on the screen (you should see an Android robot in the middle of the screen), type “fastboot flash recovery recovery-twrp.img” (no quotes) in the command window.
  5. After the recovery has flashed (just a few seconds), select Recovery mode from the bootloader (using the volume keys on the device), then press the power button. The device should now boot into TWRP.

The stock Android ROM has a tendency to replace your new bootloader with the stock bootloader. To remedy that, we need to rename a specific file.

  1. From within TWRP, go to the Mount menu, and check the System option.
  2. Press the Home button in the lower-left corner.
  3. Go to Advanced, then File Manager.
  4. Browse to /system and select the file named “recovery-from-boot.p”, then rename the file to “recovery-from-boot.bak” and press Enter on your keyboard.
  5. Swipe to confirm your change, then press Back.

Installing SuperSU and Finishing Up

Time to install the most important app on your newly rooted device, SuperSU. This app is what gives other apps access to root.

  1. From the TWRP home screen, click Install.
  2. Find the SuperSU .zip file you previously placed on the device. If you placed it in the root folder, you should find it at the bottom of the top level of directories and files.
  3. Click the .zip file, then Swipe to Confirm Flash.
  4. Click the Home button, disconnect your USB cord, then click Reboot and System.

That’s it, you’re now rooted!

Now, go ahead and use the device as you normally would. We didn’t install a custom ROM as part of this tutorial, so you’ll be running the same old version of Android you always have, except now you can install applications that require root access. At the beginning of this tutorial, I mentioned my desire to setup a proper backup system on my device. I installed and configured the highly recommended Titanium Backup Pro. That’s right, I paid for the Pro version. Completely worth it. The backups came in handy just a few days ago, as my device decided to stop booting. I was able to wipe the device (from within TWRP), then use Titanium to restore all my applications and settings. A full backup tutorial will have to wait for a future post.

Enjoy your rooted Nexus!