visit
Let’s face it we all have been there, trying to fiddle with managing our emulators and dev devices. And at max, we would do is try to manually manage it. Let me make this clear I am not talking about tests here as that’s all related to the code. My focus here is on managing the device/emulator that’s paired with your dev environment/system (..and to your IDE — Android Studio, if you still use Eclipse you are simply oblivious to the joys of coding in Android [here is a long blank stare from me to you] ).
Technically there is a tool called ADB (Android Debug Bridge) which maintains your connection with your device/emulator and the dev environment/system. From the , it is described asOk… that sounds something of use but not convincing enough for you to try and play with it yet. Let me try and put forward some of the problems as a dev you are facing every day (..and yet no one admits to them whenever it comes up in a conversation 🙄..) and how can we solve this.adb is the command line tool provided in the Android SDK package. adb stands for Android Debug Bridge which allows you to communicate with an emulator instance or connected Android-powered device to:
1. Manage the state of an emulator or device.2. Run shell commands on a device.3. Manage port forwarding on an emulator or device.4. Copy files to/from an emulator or device.
Oh yeah ..you are used to hitting Run in the IDE (or the keyboard shortcut for the same) and BOOM the apk installs in the device. But what do you do to uninstall the apk? [Rolling eyes] oh yeah I know ..you will open up your device/emulator and manually uninstall the app by dragging it to the trash bin in the home screen and hit yes when prompted to uninstall it. Hard ain’t it? Yeah, it is.
ADB can make it as simple as executing just a command adb uninstall <package_name>if you wish to keep the data and cache directory intact but uninstall the app just add -k as an option to the command
adb uninstall [-k] <package_name>Of course, you can install an app too via adb install [-r] [-s] <package_name> the options available to the command are[ ] means it is an optional parameter
That looks neat.
-r : reinstall the app, keeping its data-s : install on SD card instead of internal storage
For our example here let’s assume we have like 3 devices and 2 emulators running, named as device_1, device_2, device_3, emu_1, emu_2.
Our end goal is to be able to execute some adb command on devices/emulator in order such asBut we wanna go a step ahead and orchestrate commands in a pattern (..by writing a bash script, obviously). But to do that I need to specifically direct commands to the device I want to control. adb -s <device_id> <command>You can also use adb -e <command> to directs command to the only connected Emulator
Now we are talking 😎. Now the only thing I gotta do is create a bash script something like this #!/bin/bashGet the device id by using adb devices
..andwhere <some_command> doesnot have to be the same.
I have seen that you also need to uncheck and then check ADB Integration inside Android Studio as an extra step.
It changes when you wanted to do the same task again and again. When you want to automate things adb commands come in handy. You can even add them to a script and run it every time one of the tasks completes.
To push a file/dir to device
adb push <local> <remote>where <local> is file in your local system i.e my_image.png and <remote> is file location in device/emulator i.e /sdcard/Downloads/my_image.png
adb push ~/Downloads/my_image.png /sdcard/Downloads/my_image.pngTo pull a file/dir from device
adb pull <remote> [<local>]where <local> is file in your local system i.e my_image.png and <remote> is file location in device/emulator i.e /sdcard/Downloads/my_image.png
adb pull /sdcard/Downloads/my_image.png my_image.pngGenerate Public/Private Key
adb keygen <filename>The private key is stored in <file>, and the public key is stored in <file>.pub Any existing files are overwritten.
Get a bug report
Get list of all connected devices
adb devices
Logcat Format
To define the format of each log entry that is dumped , you need to set the output format for log messages
Filter your log data
A few people would say that we can always use | grep “filter_text” appended to the adb logcat. Well, you are right you can, but there are some neat tricks hidden in the actual implementation of logcat and you should look at them too.
adb logcat <options> <process-tag>:<priority-code>List of all priority codes that can be used in the “logcat” command:
When filters are provided, the logcat command will dump log entries that are generated from specified processes with priorities higher than the specified code, plus all log entries that generated from unspecified processes.A wildcard character, *, can be used to represent all processes
This is pretty well known to people who are into Modding their device. But for people who aren’t going to mess with their device, here is what you can do with ADB
Thanks for reading! Be sure to click ❤ below to recommend this article if you found it helpful.
You can connect with me on , , , , and