Blograby

Using the Command-Line Tool

The command line is a place where you can run an application, navigate between directories, and perform specific tasks by just typing commands. For a novice, using the command line may seem intimidating at first, but once it’s mastered, it’s powerful and fast. If you are interested in emerging technology, the command line may be the only way initially to test applications, as UIs are usually the last component built in software development.

A Basic Review

To use the command line on the Mac, open the Terminal window. On Windows, press Shift-Right click and the context menu will display an Open command window. The key is to understand how to point or navigate to the application you want to use, whether you want to use it on its own or to execute commands on other files located in other directories.

Here are some commonly used commands, along with a brief explanation of each:

cd dirname goes to another directory
cd “some name” if directory’s name has space, put it in quotes
cd some name or escape with the backslash
ls lists files in a particular directory
.. cd goes to the parent directory of current directory
cd goes to the home directory from wherever you are

For the purposes of this chapter, we want to easily run commands from the Android SDK. Let’s assume that it is on the desktop. Open the Terminal window; you should be at the top level of your user directory. Type the following:

cd Desktop

You should now see the path to the desktop. Type the following to see the list of all files on your desktop:

ls

Or type the following to see their date of creation, size, and permissions for visible and hidden directories:

ls -al

To run simple commands, you can navigate down to the tools directory, or enter the full path using a forward slash between directories followed by the command, as follows:

androidSDK/platform-tools/adb devices

If you want to access another directory from this location, you need to identify and type long instructions. Let’s go over the command to install the AIR runtime emulator to use it with the Android emulator. For the sake of this example, both the Android SDK and the AIR SDK are on the desktop. Type the following command on one line:

androidSDK/platform-tools/adb -e install
AIR_SDK/runtimes/air/android/emulator/Runtime.apk

This method works, but as you can see, it is cumbersome.

The PATH environment variable

To avoid typing long paths between directories, you can store them in an environment variable called PATH, which lists directories so that you don’t have to provide their full path every time. The shell, a program that reads what you type and responds appropriately, looks for commands in the list of directories stored in PATH.

On the Mac, to check what the variable stores, type:

echo $PATH

On Windows, type:

echo %PATH%

Let’s add the Android directory to our variable. The value of PATH is the current value plus the new location. Values are separated by a colon and should not have any empty spaces.

This is the instruction for my Mac. I placed the android directory on my desktop, renamed to androidSDK for convenience:

export PATH=$PATH:/Users/Veronique/Desktop/android-sdk/platform-tools

 

Be careful to follow the instructions exactly as indicated. Do not delete the existing PATH variable. You want to add to it, not replace it. If you are hesitant, practice the command in the preceding paragraph, but
without the word export; doing so will only change the PATH variable while the Terminal window is open. For best performance, add the directories less often used at the end.

Now that it is stored, try the same command as before, but without the path to the android directory:

adb devices

For Windows, the principle is the same. Please refer to the instructions on the Adobe website, or go to http://help.adobe.com/en_US/air/build/WSfffb011ac560372f-71994050128cca87097-8000.html or  http://polygeek.com/2958_flex_creating-your-first-air-app-for-android-using-flash-builder.

Conclusion

We have now concluded our introduction on tooling and have built a basic application. Most information from this point on will be tool-agnostic.

Exit mobile version