Flash with Fastboot

This page provides details for flashing Android builds onto devices using the fastboot and adb tools. These tools let you connect your development workstation directly to your Android-powered device so you can install (flash) Android and test your OS and app changes. For additional information on how adb works, with emphasis on app development, see Android Studio's Android Debug Bridge (adb) page. If you want details on the code for adb, see the adb README.

Verify that you have fastboot and adb

When you build Android, adb is built by default. To confirm you have adb, run the following commands:

adb --version
fastboot --version

If you see version numbers, you have fastboot and adb installed. If you don't see version numbers, ensure you built Android. successfully. Continue to Enable your USB connection.

Enable your USB connection

Before running Android on a device, you must enable your USB connection:

  1. Enable OEM unlocking and USB debugging in the developer options:

    1. In the Settings app, tap About phone.
    2. Tap Build number seven times.
    3. When you see the message You are now a developer!, tap <-.
    4. Tap System, then tap Developer options.
    5. Enable OEM unlocking and USB debugging. If OEM unlocking is unavailable, connect to the internet so the device can check in. If that still doesn't work, you can force a check in: In the Dialer app, enter *#*#CHECKIN#*#* (*#*#2432546#*#*) (no SIM required). After entering the number (no need to press call), the text disappears and a success notification appears.

    If OEM unlocking remains unavailable, your device might be SIM locked by your carrier and the bootloader can't be unlocked.

  2. Connect your device to a USB port on your workstation.

Boot into Fastboot mode

Before Android can be flashed to a device, a device must be in Fastboot mode. There are two ways to boot a device into Fastboot mode:

  • Use the adb command: From the command-line, type adb reboot bootloader.
  • Use a key combination:
    1. Determine the key combination for your device. For a table of Fastboot key combinations, see Fastboot key combinations.
    2. Turn the device off.
    3. Turn the device on and immediately hold down the key combination for your device (determined in step 1).

Unlock the bootloader

After booting into fastboot mode, you must unlock the bootloader.

To unlock the bootloader:

  1. (Optional) Back up any important files on the device.
  2. Run the unlock command for your device:

    • If you're updating a Nexus or Pixel device that is manufactured in 2015 or later, run fastboot flashing unlock.
    • For Pixel 2: To flash the bootloader, verify that the Pixel 2's bootloader is updated to at least Oreo MR1's version. To update to a Pixel 2 to this version, apply the over-the-air (OTA) update or sideload a full OTA.
    • For Pixel 2 XL only with loader version prior to TMZ20a: The critical partitions might need to be unlocked before flashing. To unlock the critical partitions on Pixel 2 XL only, run fastboot flashing unlock_critical.
    • If you're unlocking a pre-2015 device, run fastboot oem unlock.

    The target device displays a confirmation screen.

  3. Confirm that you want to erase all user data and unlock the device.

Flash a device

You can flash an entire Android system in a single command. Flashing an entire system with a single command verifies that the system being flashed is compatible with the installed bootloader and radio, writes the boot, recovery, and system partitions together, and reboots the system.

To flash a device:

  1. Place the device in fastboot mode by holding the appropriate key combination at boot or using the following command:

    adb reboot bootloader
    
  2. After the device is in fastboot mode, run:

    fastboot flashall -w
    

The -w option wipes the /data partition on the device, which is useful for your first time flashing a particular device.

Re-locking the bootloader

To re-lock the bootloader:

  • For 2015 or later devices, run the command fastboot flashing lock
  • For 2014 or earlier devices, run the command fastboot oem lock

Restore device to factory state

Factory images for Google devices are available from Factory Images for Nexus and Pixel Devices. Factory images for the Motorola Xoom are distributed directly by Motorola.