DEV Community

Kabue Charles
Kabue Charles

Posted on

Connect/debug android with adb (Android Debug Bridge) commands in terminal easily, with one or many devices/emulators.

Alt Text

If you are developing/debugging an android app, sometimes you may want to run some commands from the terminal (using adb). If you have one device/emulator attached, then you are okay to run commands like adb install -r app.apk.

But when you do have several devices attached, that command will not work. You would have to specify the ID of the specific device you want to run a command on: adb {deviceid} install -r app.apk. Now, to get a list of attached devices, you simply run the command: adb devices

$ adb devices
List of devices attached
emulator-5556 device product:sdk_google_phone_x86_64 model:Android_SDK_built_for_x86_64 device:generic_x86_64
emulator-5554 device product:sdk_google_phone_x86 model:Android_SDK_built_for_x86 device:generic_x86
0a388e93      device usb:1-1 product:razor model:Nexus_7 device:flo

This is why I wrote below bash script:



This script allows you to connect/debug android with adb commands in terminal easily, with one or many devices/emulators.

bash <(curl -s https://gist.githubusercontent.com/McKabue/ac124f736085e9650fdbf63b1d9ca5ab/raw/ccfba9fad913baebc1f08cbcd7e525cc3827dd5a/debug-android-from-terminal.sh) install -r app.apk

This will prompt you to run the command on a specific device, or all of them.

Discussion (0)