Android Device

ADB is your friend

When connecting real device to an android build machine for debugging, ADB is your friend. We discussed ADB briefly in "Tools to know - ADB" section, and we will explore more in this section.

ADB comes with Android SDK and available in ANDROID_HOME/platform-tools. You can check by launching "android sdk" from command line, which pops up the below UI. On my machine as you can see , it is already installed (We make an assumption here that you have android sdk installed and configured with PATH variables)

Verify that Android SDK platform-tools are installed by opening SDK manager

Enable USB Debug

Before connecting your real device via USB to the computer, we have to first enable Developer options, since only then will ADB be able to talk to this device.

Starting with Android 4.2 and higher, the developer options screen is not visible under Settings. To make it visible, go to Settings > About phone and tap Build number seven times. Now once you return to the previous screen, the option should be visible now.

For more read here

Variations of the above image might be based on your device.

Connect device

Now connect the device using a USB cable to your computer.

Open a command prompt (or shell if you are on mac) and type "adb devices". It should list all devices that are connected (and have usb debugging enabled)

If all goes well, you should see that your device is recognized as below

Note: You might have to shift your eyes between the device and the console that launched adb back and forth.

Troubleshooting Tips

The below examples are on Windows, but the same applies to a Mac too.

Sometimes, you might see an "unauthorized" word instead of device as below (The reason this generally happens is because of an improper handshake between device and pc/mac. The RSA fingerprint should be generated and the pc/mac should have the public key and you should see a pop up on the device to accept the connection). The effect of that "unauthorized" is that any commands subsequently will throw an error like the below $ADB_VENDOR_KEYS not set

C:\Users\pmacharl>adb devices
List of devices attached
209c6111        unauthorized

C:\Users\pmacharl>adb tcpip 5555
error: device unauthorized.
This adbd's $ADB_VENDOR_KEYS is not set; try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.

To solve the unauthorized problem, delete the files "adbkey,adbkey.pub" from all of these locations (It is okay because the files are generated everytime the device is connected if one is not found)

#Windows machine
c:\users\<username>\.android
c:\android\.android
c:\window\system32\config\systemprofile\.android
#Mac
~/.android
~/.AndroidStudioXX/.android

After deleting the files, restart adb with "adb kill-server" and then "adb start-server". At this point, you should see a pop up on the device to accept the connection, click yes.

USB Drivers

You might have to have the right USB drivers installed on your pc/mac to view this. Your manufacturer might give this, otherwise you can try google usb driver as below.

After you install google usb driver, go to Device manager and update driver for the device. If necessary, update driver and point it to the downloaded google usb driver folder located in sdk (Force the driver to be installed)

results matching ""

    No results matching ""