Let’s examine what is available in tools and platform-tools directories of your Android SDK. I will be using Linux machine for this blog, but adjustements for Win environment are minor ones and rather obvious.
Before you start, make sure that both directories have been added to your computer PATH.
There is a number of scripts and executables in this directory (there are directories, too, but we are not looking at them now).
Today we’ll examine a script named android. If you launch it with –help option (android –help), you will see something like this:
android script provided us with a list of options and so-called “verbs” it understands. Verbs actually mean certain actions that can be performed by the script. Those actions fall into 3 groups:
- AVD (Android Virtual Device) management (create, move, delete AVD etc)
- Android project management (create, update an Android project)
- ADB (Android Debug Bridge) and Android SDK update
Basically, these are functions of SDK Manager and android is the main script which launches SDK Manager. You can easily verify this by executing the script without parameters: in such case it will launch SDK Manager GUI which we already have seen while installing Android development environment.
You can use android script for all those functions, but, frankly, SDK Manager GUI is handier, so I would not use the script in command-line mode unless I want to write certain automation scripts that require its functions.
Next tool which we are going to look at is emulator executable. This is actually an interpreter which runs AVDs. This executable is used by Eclipse IDE under the cover to launch Android device emulator. But you can launch it from command line as well. If you followed me in installing Android development environment, you already should have had at least one AVD available. You can verify this by using android script. Type this in your command shell:
android list avd
This will list you all AVD you have on your computer with certain details on them. If you have AVD indeed, you can launch emulator to execute the AVD. If you don’t, launch SDK Manager by executing android script without any parameters. This will provide you with SDK Manager GUI and there is a tab for creating AVDs. Create AVD and proceed.
There are two equal ways of launching emulator to run AVD. Type in your command shell:
emulator -avd NameOfYourAVD
or this:
emulator @NameOfYourAVD
Of course, use a name of your existing AVD instead of NameOfYourAVD. Both commands will launch the AVD and you’ll see the emulator GUI:
Next we are going to look at adb command-line tool. adb stands for Android Debug Bridge. This is an executable which allows other applications to connect to either Android emulator or a real device if such is connected to your computer.
While the emulator is still running, type this in the command-line shell:
adb devices
You will see something like this as adb output (it may take several seconds to start adb, so be patient):
List of devices attached emulator-5554 offline
This output shows that adb is aware of emulator instances running and their state. If there is no emulator/device running, adb returns
no device
.
Unlike android script, adb has a lot of functions. You can see a list of them if you type
adb help
If you just want to do a basic development, you probably don’t need to know much about adb; it will be operating “behind the scene” for you. However, if you consider yourself as an advanced developer, you may want to learn more about adb here.
To give you examples, here are just some of adb functions:
- Copy Android application (apk file) to an emulator or a device and install it there (install command)
- Copy arbitrary files to and from an emulator or a device (push and pull commands)
What I personally like most among adb functions, is a real Unix/Linux shell. Type this:
adb shell
and adb will present you with a shell prompt (# in my case). To make sure it is the shell indeed, type ls (Unix/Linux analog of dir command on Windows) and you will see filesystems mounted on your running AVD:
No comments:
Post a Comment