SL4A - Navigating the Android SDK


Advertisements

A software development kit that enables developers to create applications for the Android platform. The Android SDK includes sample projects with source code, development tools, an emulator, and required libraries to build Android applications. This chapter discusses the Android SDK and ways to use it for developing the code targeted at SL4A.

SDK Components

The directory tree where you installed the Android SDK, contains a list of folders containing documentation, sample code and a number of tools. Navigating to the tools subdirectory reveals a number of executable files.

Discussed below are some important components within the Android SDK.

SDK Manager

The Android SDK Manager separates the SDK tools, platforms, and other components into packages for easy access and management. The SDK can be configured to check for new or updated SDK packages and add-on tools.

Android SDK Manager

By default, Android Studio does not check for Android SDK updates. To enable automatic Android SDK checking −

  • Step 1 − Choose FileSettingsAppearance & BehaviorSystem SettingsUpdates.

  • Step 2 − Check the Automatically check updates for Android SDK checkbox and select an update channel.

  • Step 3 − Click OK or Apply to enable the update checking.

The SDK Update Sites tab displays the sites that Android Studio checks for Android SDK and third-party updates. You can add other sites that host their own Android SDK addons, then download the SDK add-ons from those sites.

Android Emulator

The AVD Manager provides a graphical user interface in which you can create and manage Android Virtual Devices (AVDs), which are required by the Android Emulator. An Android Virtual Device (AVD) consists of a number of files including configuration and virtual storage required by the emulator. You can create as many AVDs as you want for simulating different devices.

The following steps can be used to create an AVD in Eclipse −

  • Step 1 − Select WindowAVD Manager.

  • Step 2 − Click New.

  • Step 3 − Type the name of the AVD, choose the target and specify values for the other features.

  • Step 4 − Click Create AVD.

For devices with keyboard, there is a standard set of mappings from the host keyboard to actions on the device. The default Emulator key mappings are −

Emulator Key Mapping on Host Device
BUTTON_CALL F3
BUTTON_HANGUP F4
BUTTON_HOME Home
BUTTON_BACK Escape
BUTTON_MENU F2, PageUp
BUTTON_STAR Shift+F2, PageDown
BUTTON_POWER F7
BUTTON_SEARCH F5
BUTTON_CAMERA Ctrl+Keypad_5, Ctrl+F3
BUTTON_VOLUME_UP Keypad_Plus, Ctrl+F5
BUTTON_VOLUME_DOWN Keypad_Minus, Ctrl+F6
TOGGLE_NETWORK F8
TOGGLE_TRACING F9
TOGGLE_FULLSCREEN Alt-Enter
BUTTON_DPAD_CENTER Keypad_5
BUTTON_DPAD_UP Keypad_8
BUTTON_DPAD_LEFT Keypad_4
BUTTON_DPAD_RIGHT Keypad_6
BUTTON_DPAD_DOWN Keypad_2
TOGGLE_TRACKBALL F6
SHOW_TRACKBALL Delete
CHANGE_LAYOUT_PREV Keypad_7, Ctrl+F11
CHANGE_LAYOUT_NEXT Keypad_9, Ctrl+ F12
ONION_ALPHA_UP Keypad_Multiply
ONION_ALPHA_DOWN Keypad_Divide

You can change these settings by editing the default.keyset file in the .android subdirectory.

Android Debug Bridge

ADB, Android Debug Bridge, is a command-line utility included with Google’s Android SDK. ADB can control your device over USB from a computer, copy files back and forth, install and uninstall apps, run shell commands, and more.

If you have an emulator running and a real device connected, you must specify where you want the ADB commands to a real device, use the option − d and for the emulator, use –e. Following is the list of flags and commands for ADB.

S.No. ADB flags & Description
1

-d

Directs device to the only connected USB device; returns an error if more than one USB device is connected.

2

-e

Directs command to the only running emulator; returns an error if more than one emulator is running.

3

-s <serial_number>

Directs command the USB device or emulator with the given serial number.

4

devices

List all connected devices

5

connect <host>:<port>

Connect to a device via TCP/IP

6

disconnect <host>:<port>

Disconnect from a TCP/IP device

S.No. ADB commands & Description
1

adb push <local> <remote>

Copy file/dir to device

2

adb pull <remote> [<local>]

Copy file/dir from device

3

adb sync [<directory>]

If <directory>is not specified, both /system and /data partitions will be updated. If it is “system” or “data”, only the corresponding partition is updated.

4

adb shell

Run remote shell interactively

5

adb emu <command>

Run emulator console command

6

adb logcat

View device log

7

adb forward <local> <remote>

Forward socket connections

8

adb install [-l] [-r] [-s] <file>

Push this package file to device and install it. (-l forward lock the app)

(-r reinstall the app, keeping its data)

(-s install on SD card instead of internal storage)

9

adb uninstall [-k] <package>

Remove this app package from the device. -k means keep the data and cache directories

10

adb bugreport

Return all information from the device that should be included in the bug report.

11

adb help

Show this help message

12

adb version

Show version number

The Shell

A shell is a program that listens to keyboard input from the user and performs actions as directed by the user. The adb shell command provides Unix to send shell commands to an emulator or a connected device and display the results. It can also be used to launch an interactive shell locally.

To issue a single command without entering a remote shell, use the shell command like this −

adb [-d|-e|-s <serialNumber>] shell <shell_command>

Or to enter a remote shell on an emulator/device −

adb [-d|-e|-s <serialNumber>] shell

When you are ready to exit the remote shell, press CTRL+D or type EXIT.

Dalvik Debug Monitor Service

Android ships a debugging tool, Dalvik Debug Monitor Service (DDMS). This tool provides additional services such as port-forwarding services, screen capture on device, incoming call and SMS spoofing etc.

Dalvik Debug Monitor Service

When DDMS starts, it connects to adb. A VM monitoring service is created between adb and DDMS, when a device is connected. This service notifies DDMS when a VM on the device is started or terminated.

Once the VM starts running, its process id is sent to the DDMS via adb and the adb daemon opens a connection to the VM’s debugger. DDMS can now talk to the VM using a custom wire protocol.

Advertisements