× Please, log in to give us a feedback. Click here to login

You must be logged to download. Click here to login


MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation


MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Android Emulator: How to Use the Command-Line Tools

In this article, we are going to experiment with command-line applications for Android development. We will see how to run applications on the Android platform using command line tools.

The Android Software Development Kit comes with multiple tools which help us create and also compile Android applications. These tools are in place to support users developing console based applications. On the other hand, if we are doing all of our Android development work within the Eclipse system, we still should be aware of the Android Software Development Kit command-line tools and their functionality. Actually when we run Android-related functions, such as creating an Android project or running an application in the Android Emulator, we are actually calling the connections to the Android command-line tools. These Android command-line tools or command line arguments, whether run from a command-line interface or from a Graphical User Interface IDE, are the real core to the functionality of the Android Software Development Kit.

Let us start exploring the command line features one by one.

Running the ActivityCreator.bat:

The ActivityCreator.bat should be located in a path like ‘/tools/directory’. It is located inside the Android Software Development Kit. Actually most of the forward-facing command-line tools are located in the root of the tools directory. The “Forward-facing” tools are tools that in turn call other tools positioned deeper in the ‘/tools/’ directory. The ActivityCreator.bat is a specimen of a tool from the root of the tools directory that actually calls another tool when it is run in the system. Generally we are using vi (For Linux), Notepad, or any text editor, to open ActivityCreator.bat.

We will see that there is only one line of real-world code at the bottom of the file. ActivityCreator.bat is used to call ActivityCreator.exe (Executable Files) in the ‘/tools/lib/activityCreator/’ directory. The ActivityCreator.bat is a tool that is just a front end of other tools.

Figure 1: Showing command line editor

In these circumstances, we actually know that Activity Creator is used to establish our development environment to the point where it will create the initial files needed to begin developing our application.

This directory structure is the same structure as per Android system. The ActivityCreator.bat creates C.java, AndroidManifest.xml, and all other supporting files needed to begin our application. After that we can go to a command-line environment and explore the ActivityCreator.

At first click Start menu button -> click Run and type CMD or COMMAND in the Run dialog box, and click OK. After executing this command, it launches the command window shown above. This window is equivalent of the older Disk Operating System environments. With the command window open, enter ActivityCreator at the -> prompt. Actually the Microsoft command-prompt interface is not case sensitive.

When we are using a different environment that is case sensitive, such as Linux/Unix, the screenshots in this article may not show the proper case for our environment. Running the command ActivityCreator, which actually runs ActivityCreator.bat, also produces the following output:

This is an Activity Creator Script:

  activityCreator [--out outdir] [--ide intellij] ourpackagename.ActivityName

Now we will create the structure of a simple Android application. The following items will be created here:

  • AndroidManifest.xml: This is the application manifest file.
  • build.xml: An Ant script to build/package the application.
  • res: This is the resource directory.
  • src: This is the source directory.

src/our/package/name/ActivityName.java the Activity java class. The packageName is a fully capable java Package in the format <package1>.<package2>... (With at least two ingredients)

  • bin: This is the output folder for the build the script.
  • Options:
  • out <folder>: specifies where to create the files or folders
  • ide SGC: it is creates project files for SGC.

This above command simply indicates that we need to provide more information to run the ActivityCreator.In addition,, we need to pass the command a directory location within which to build our shell application.

Now go back to the command window and run the ActivityCreator with the following option (ActivityCreator also accepts path parameters with Unix-style forward slashes (/), if we are used to programming in a Unix/Linux environment):

  out c:\AndroidHelloSGC\android_programmers_guide.HelloSGCCommandLine

The --out option tells ActivityCreator that we want it to output something. This command option takes two parameters, <folder> and <package.activity>. The first part of the preceding line tells ActivityCreator to build the shell application in the nonexistent folder c:\AndroidHelloSGC.

Points to Remember: The parameters needed to successfully run ActivityCreator and set up our initial environment are the same as those required by the New Android Project wizard. Run ActivityCreator with this new command-line options and its parameter. We should see the following output from the tool:

Listing 1: Sample showing output

  C:\sgc>activitycreator --out c:\AndroidHelloSGC\ android.programers.guide.HelloS GCCommandLine
  Package: androidprogrammers.guide
  out_dir: c:\AndroidHelloSGC  activity_name: HelloS GCCommandLine
  Create directory c:\AndroidHelloSGC\src\android\programmers\guide\ HelloSGCCommandLine.java
  Create directory c:\AndroidHelloSGC\bin
  Create directory c:\AndroidHelloSGC\bin\res\values
  Added file c:\ AndroidHelloSGC\bin\res\values\strings.xml
  Create directory c:\AndroidHelloSGC\bin\res\layout
  Added file c:\AndroidHelloSGC\bin\res\values\main.xml
  Added file c:\AndroidHelloSGC\AndroidManifest.xml
  Added file c:\AndroidHelloSGC\build.xml

The following section covers the files created by ActivityCreator, because they do vary slightly from those created by Eclipse Integrated Development Environment.

Create the Hello World! Activity in the Windows Command Line Interface:

Now, we will use the Windows command-line interface to edit the project files. The project files were created in the previous sections by the ActivityCreator.bat. We will edit these files and add code to them, without using Eclipse.

Editing the Project Files:

Now we are going to edit the files. At first open main.xml in either an XML editor or Notepad if we do not have a specific Extensible Markup Language editor. This will let us edit the file and remove the <TextView/> definition that is within it.

Now we have to save main.xml as shown in the next process.

Listing 2: Sample showing xml file

  <? xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlnm:android="http://schemas.android.com/apk/res/android"

This above code sets the size, orientation, height, width of the system. The result of saving main.xml is an empty shell. This gives us a platform on which to edit our <activity>.java file. The <activity>.java file is in a folder which is quite a lot of directories deep, AndroidHelloSGC\src\android\programmers\guide.

To create our Hello SGC! Application, and add the following lines to create, set, and use a Text View:

Here the HelloSGC JFD is starting to develop the code as well as create TextView control.

  TextView HelloSGCTextView = new TextView(this); //Execute the text view control

Now we are working in the new process to show message.

  HelloSGCTextView.setText("Hello SGC!");
  /*Set ContentView to TextView */

Some protocol should be Remembered when we are adding the TextView package to the beginning of every file.

The finished HelloSGCCommandLine.java file should look like the following. In the following program we have tried to write working procedure for every code.

Listing 3: Sample showing the complete example

  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  public class HelloSGCCommandLine  extends Activity
                    //called when the activity at first created
                    public void onCreate(Bundle icicle)
                                      // Hello SGC
                                      // BEGIN
                                      //Create TextView
                                      TextView HelloWorldTextView = new TextView(this);
                    /* Set text to Hello SGC*/ 
                    HelloSGCText.setText("Hello SGC...");
                    /* Set ContentView to TextView */

Our project files should now be set. After that we have to compile our program and run it in the Android Emulator System.

Adding the JAVA_HOME Variable:

Before we try to compile our project, we must add another environment variable to our PC—JAVA_HOME—that points to our JDK (Java Development Kit). Even if this path is in our PATH statement, we still need to create a new variable named JAVA_HOME.

Points to Remember:

Some points are very much necessary to remember. The JAVA_HOME variable is needed only if we are working in the command-line environment. On the other hand, if we are exclusively working in the Eclipse IDE then we do not need to add it.

  1. Right-click My Computer and select Properties.
  2. Select the Advanced tab on the System Properties window and click the Environment Variables button. This will open an Environment Variables window.
  3. Click the New button to add a new variable named JAVA_HOME. The value for the variable should be the full path to our Java SDK, as seen in the following illustration.

Figure 2: Open System Properties and Click on Advanced Option

Figure 3: Select JAVA_HOME VARIABLE and set the path

Compiling and Installing the Application:

It is time for the real time testing process. We can now compile our command-line project. To compile our project, use ANT process. Once the project is compiled, we can easily install it on our Emulator or Phone.

Compiling Our Project with ANT:

After we have our JAVA_HOME environment variable set and have ANT in our PATH statement, we should be able to navigate the directory containing our build.xml file and simply run the command ant.

Open a Windows command prompt to our project directory and run the ant system as follows:


The result of running ant will be an .apk (extension of the Android file) file that we will install directly in our phone (Emulator). Nevertheless the Eclipse installs the .apk file for us directly on the Emulator; but here we need to install it manually as a step by step process. We will use the Android Debug Bridge (adb) Android tool to install the application.

Installing Our Application with adb:

The first step is to start the Emulator. In the Android /tools folder, find the emulator.exe file and execute it as per our requirement. This starts our Android server. It also starts a virtual cell phone on our Personal Computer. We can then use different tools to interact with the.

To install our command-line application on our Android server we need to use adb. Adb (Android Debug Bridge) is our connection to the Android server which is started with our Emulator .The adb contains many useful functions that allow us to interact with our Android server. One of these enables us to install applications also.


Command or Syntax



install <path>

This is used to Install applications to the server.


pull <remote file> <local file>

It Pulls a remote file off the server.


push <local file> <remote file>

It Pushes a local file to the server.



It can open a shell environment on the server.


forward <local port> <remote port>

It can forward traffic from one port to another and from the server point.



It Starts the server.



It Stops the server.


ppp <tty> <params>

It uses a PPP connection over USB.



It shows the lists of available emulators



It shows the lists of adb (Android Debug Bridge) commands



It shows the ADB (Android Debug Bridge) version

Table 1:Table shows the commands

Now to copy our application to the server, open a Windows command prompt and navigate to the directory of our build.xml file. Actually the command syntax for adb (Android Debug Bridge) is as follows:

adb install <apk path>

When the application is installed in the phone properly, we will just get the package size as response in return from the command. This is the command given here.

  C:\sgc>abd install c:\androidhelloSGC\bin\HelloSGCCommandLine.apk
  71 KB/s (3970 bytes in 0.054s)

Now some points should be remembered that the Android is an operating environment. The commands that we can use within the shell are standard POSIX commands. On the other hand, the Android server, user-installed applications are kept in the /data/app directory.

Using compact disk, navigate to the app directory where all types of the command are given as shown below.

  C:\SGC\abd shell
  #cd data
  cd data
  #cd ap
  cd app

After writing the command we can run the command ‘ls’ that can list all the files in this directory. We should see a file named HelloSGCCommandLine.apk. This file represents the installation of our application. Now that we have located the application on the Android server and we also can remove it from the system.

Use the command and the syntax ‘rm’ (Remove Directory) HelloSGCCommandLine.apk to remove the application from the system. A subsequent use of the ‘ls’ command, shows that particular file has been removed from the system.

Process to Uninstall a Prior Version of an Activity:

Before we add the file to our running Android server, we are going to uninstall the prior version of HelloSGCCommandLine. Uninstalling a previous version of an application before we install another is not required because some system updates it automatically.

To start with, go ahead and uninstall our previous version before proceeding with our Android Emulator open. After that return to our command prompt environment and run the command adb (Android Debug Bridge) shell, which will open the shell environment of the Android server. If we are successful, then our command prompt should turn from a > to a#. Now, we have an open shell into our Android server. There are a lot of functions we can run from this point. Nevertheless for now, focus on one point that is removing the old HelloSGCCommandLine.apk file.

The commands that we can use within the shell are standard POSIX (PortableOperatingSystemInterface) commands. Actually,. Basically it is a family of standards identified by the IEEE (Institute of Electrical and Electronics Engineers) for sustaining compatibility between operating systems. POSIX also defines the application programming interface (API), besides command line shells and utility interfaces. It is designed for the software compatibility with variants of the UNIX and other operating systems.

On the Android server, the system user installed applications are kept in the /data/app directory. Also we can us cd [change directory], command that navigates to the app directory, as shown in the following command.

  C:\users\SGC\abc shell
  # cd data
  cd data
  #cd app
  cd app 

Run the command ‘ls’ that shows the list of all the files in this directory system. We should see a file named HelloSGCCommandLine.apk. This file represents the installation of our Activity protocol.

Now, we have to locate the application on the Android server, so that we can remove it from the system. We can use the command syntax like ‘rm’ (remove directory) HelloSGCCommandLine.apk to remove the application. The resulting illustration shows that the rm command. If run it correctly then no feedback will be generated. A successive use of the ‘ls’ shows that the file has been removed from the system as per the Linux Command.

 C:\Users\SGC\abd shell
  # cd data
  cd data
  #cd app
  #rm HelloSGCCommandLine.apk
  rm   HelloSGCCommandLine.apk

Points to Remember: We should remember that we are technically logged into a Linux server via a shell programming, so all the commands that we run in the shell are too case sensitive.

Reinstalling and Launching the Application: Reinstall and launching may occur as per our requirement. We can now reinstall the application using ADB (Android Debug Bridge).Once the application is installed back to the server, switch to our Emulator. Launch the application from the previous loading process. We have covered the process for creating and editing files on Windows. Let’s take a look at it on Linux. Even if we are die-hard Windows users, we may want to pay attention to the following section. I have found that there are definite advantages to programming with open source tools.

Hello SGC on Linux Operating System: Many programmers/developers, especially those who are very much interested in open source software, use Linux as their platform of choice. Google and the open Handset Alliance have made an Android Software Development Kit just for these programmers. The Software Development Kit is actually the same Software Development Kit (because Java is portable and platform independent), but the tools are created specifically to run on Linux.

We will be working on linux command mode processes and we will use an older version of Red Hat Linux (Red Hat 9) as Linux platform. At first we downloaded and installed Eclipse and the Android Software Development Kit.

Though, it quickly became apparent that there are limitations to the version of the Linux that we can safely run Android on. As a minimum requirement, we have to have a version of Linux that supports libstdc++.

The Android documentation lists the Ubuntu Dapper Drake as a tested version of Linux. If we do not have that then a decision has to be taken as to which version we want to use. Unfortunately, with the hardware that we are running, we had a problem to install the latest version of Ubuntu. So we decided to move away from whatever recommended and try something new.

When we made the decision to drop Red Hat for another distribution of the Linux, we decided to try Fedora 8. The remainder of this article uses Linux screen shots from Fedora 8; though they should work without any issue on other distribution as well.

Points to Remember: If we choose to use Fedora 8s, it comes packaged with a custom version of Eclipse called Fedora Eclipse. If we attempt to install the Android plugin (using the steps outlined earlier in this article) for Fedora Linux, it will throw an error stating that the plugin org.eclipse.wst.sse.u is required. We can address this in either of two ways: one way is to download the latest version of the Eclipse for Linux, and the other is to use Fedora’s (one types of Linux Operating System) automatic update program, which will download an update to Fedora Eclipse that will bring it up to date with the latest version of Eclipse. We can then use this version of Eclipse with the Android Software Development Kit.

Configuring the PATH Statement of Android:

Now we will think about the Configuration procedure of the PATH statement of the Android. Actually it is the first step to configure our PATH statement. The path is the list of directories within which the operating system will look when trying to find a command that is being run. To see what our path is correctly configured here, run the following from a terminal:

  echo $PATH
  [jfdimage@new-host-2 ~]$ echo $ PATH
  /usr/lib/qt-3.3/bin/:usr/Kerberos/bin:/usr/lib/ccache:usr/local/bin:/usr/bin:usr/X11R6/bin:/ home/jfdimage/bin 
  [jfdimage@new-host-2 ~]$

Here we have used the export command to add Android to the PATH statement (according to the next illustration process):

  export PATH=$PATH:<android path>
  [jfdimage@new-host-2 ~]$ echo $ PATH
  /usr/lib/qt 3.3/bin:/usr/Kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:bin:/usr/X11R6/bin:/home/ jfdimarzio/bin
  [jfdimage@new-host-2~]$export PATH= $PATH:/home/jfdimage/Android/tools

Editing the PATH statement, actually it is like in Linux that will change the PATH statement only for the current terminal session. To make our PATH statement change permanent, we must edit bash_profile. Use vi to edit bash_profile, as shown in the following illustration.

  [jfdimage@new-host-2 ~]$ vi .bash_profile

With .bash_profile open in the vi editor (Editor in Linux), use the command like: i to put vi in insert mode, and then add Android to the PATH statement. Then press the ESC key, use the command: w to write the file and then use: q to quit from the system. And now you are ready to use linux environment to write and deploy your android application.

Basically the command line arguments are part of the Character User Interface. Command process means we are working on Disk Operating System protocol scenario. Here we are very much dependent on the architecture of typing process. So developers use this system for high level security purpose. We know that when a system is very much user friendly then everyone can easily access its features through the drag drop, clicking process etc. But we know that if this system is totally written under the command line base, then it is ensured that only knowledgeable persons can understand the logic but others cannot understand the logic or syntax. In these circumstances, we have described the command line processes and its usage in a step by step process. If anyone gives wrong data into the command prompt then actually it will display error output. In this article we have tried to give all types of command that are often used in the command prompt. We have also discussed some standard codes that are very much important in our android system. Actually, when we are writing code in Eclipse Intergraded Development Environment then it is working with different Graphical User Interface features. But in command prompt, we need to know the correct commands to perform similar tasks.

Website: www.techalpine.com Have 16 years of experience as a technical architect and software consultant in enterprise application and product development. Have interest in new technology and innovation area along with technical...

What did you think of this post?
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!

> More info about MrBool Credits
You must be logged to download.

Click here to login