Android 简明教程

Android - Developer Tools

安卓开发者工具可让你为安卓平台创建互动且强大的应用。这些工具通常可归类为两种类型。

The android developer tools let you create interactive and powerful application for android platform. The tools can be generally categorized into two types.

  1. SDK tools

  2. Platform tools

SDK tools

不管使用哪种安卓平台,SDK 工具通常与平台无关,并且是必需的。当把 Android SDK 安装到你的系统时,这些工具会自动被安装。SDK 工具列表如下 −

SDK tools are generally platform independent and are required no matter which android platform you are working on. When you install the Android SDK into your system, these tools get automatically installed. The list of SDK tools has been given below −

Sr.No

Tool & description

1

*android*This tool lets you manage AVDs, projects, and the installed components of the SDK

2

*ddms*This tool lets you debug Android applications

3

*Draw 9-Patch*This tool allows you to easily create a NinePatch graphic using a WYSIWYG editor

4

*emulator*This tools let you test your applications without using a physical device

5

*mksdcard*Helps you create a disk image (external sdcard storage) that you can use with the emulator

6

*proguard*Shrinks, optimizes, and obfuscates your code by removing unused code

7

*sqlite3*Lets you access the SQLite data files created and used by Android applications

8

*traceview*Provides a graphical viewer for execution logs saved by your application

9

*Adb*Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device.

我们将在此讨论三个重要的工具,即安卓、ddms 和 sqlite3。

We will discuss three important tools here that are android,ddms and sqlite3.

Android

安卓是一款开发者工具可让你执行以下任务:

Android is a development tool that lets you perform these tasks:

  1. Manage Android Virtual Devices (AVD)

  2. Create and update Android projects

  3. Update your sdk with new platform add-ons and documentation

android [global options] action [action options]

DDMS

DDMS 代表 Dalvik 调试监视器服务器,可以在设备上提供多项服务。该服务包括消息形成、呼叫欺骗、捕捉屏幕截图、探索内部线程和文件系统等。

DDMS stands for Dalvik debug monitor server, that provide many services on the device. The service could include message formation, call spoofing, capturing screenshot, exploring internal threads and file systems e.t.c

Running DDMS

从 Android 工作室点击 Tools>Android>Android device Monitor

From Android studio click on Tools>Android>Android device Monitor.

How it works

在安卓中,每个应用程序都在自己的进程中运行,每个进程在虚拟机中运行。每个 VM 都会公开一个唯一的端口,调试器可以连接到该端口。

In android, each application runs in its own process and each process run in the virtual machine. Each VM exposes a unique port, that a debugger can attach to.

DDMS 启动时,它会连接至 adb。连接设备后,将在 adb 与 DDMS 之间建立一个虚拟机监控服务,当设备上的虚拟机启动或终止时,通知 DDMS。

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

Making SMS

向模拟器发送短信。我们需要按照如下所示调用 telnet 客户端和服务器:

Making sms to emulator.we need to call telnet client and server as shown below

sms android

现在,单击发送按钮,您会在模拟器窗口中看到一条短信通知。如下所示:

Now click on send button, and you will see an sms notification in the emulator window. It is shown below −

sms

Making Call

在 DDMS 中,选择模拟器控件选项卡。在模拟器控件选项卡中,单击语音,然后开始输入呼入号码。如下图所示:

In the DDMS, select the Emulator Control tab. In the emulator control tab , click on voice and then start typing the incoming number. It is shown in the picture below −

call

现在,单击通话按钮向您的模拟器拨打电话。如下所示:

Now click on the call button to make a call to your emulator. It is shown below −

call1

现在,单击 Android 工作室窗口中的挂断以终止通话。

Now click on hangup in the Android studio window to terminate the call.

只需使用鼠标将通知窗口拖到中心,就可以在通知中查看假短信和通话。如下所示:

The fake sms and call can be viewed from the notification by just dragging the notification window to the center using mouse. It is shown below −

notification ddms

Capturing ScreenShot

您还可以捕获模拟器的屏幕截图。为此,在设备选项卡下的右侧查找相机图标。只需将鼠标指向它并选择它。

You can also capture screenshot of your emulator. For this look for the camera icon on the right side under Devices tab. Just point your mouse over it and select it.

只要您选择它,它就会启动屏幕捕获过程,并将捕获模拟器当前处于活动状态的任何屏幕。如下所示:

As soon as you select it , it will start the screen capturing process and will capture whatever screen of the emulator currently active. It is shown below −

ddms4

使用 Ctrl + F11 快捷键可以更改 eclipse 方向。现在,您可以保存图像或旋转图像,然后选择完成以退出屏幕捕获对话框。

The eclipse orientation can be changed using Ctrl + F11 key. Now you can save the image or rotate it and then select done to exit the screen capture dialog.

Sqlite3

Sqlite3 是一款命令行程序,用于管理 Android 应用程序创建的 SQLite 数据库。该工具还允许我们即时执行 SQL 语句。

Sqlite3 is a command line program which is used to manage the SQLite databases created by Android applications. The tool also allow us to execute the SQL statements on the fly.

您可以通过两种方式使用 SQlite,从远程 shell 或本地使用。

There are two way through which you can use SQlite , either from remote shell or you can use locally.

Use Sqlite3 from a remote shell.

使用以下命令输入远程 shell:

Enter a remote shell by entering the following command −

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

从远程 shell 启动 sqlite3 工具,输入以下命令:

From a remote shell, start the sqlite3 tool by entering the following command −

sqlite3

调用 sqlite3 后,您可以在 shell 中发出 sqlite3 命令。要退出并返回到 adb 远程 shell,请输入 exit 或按 CTRL+D。

Once you invoke sqlite3, you can issue sqlite3 commands in the shell. To exit and return to the adb remote shell, enter exit or press CTRL+D.

Using Sqlite3 directly

将数据库文件从设备复制到您的主机。

Copy a database file from your device to your host machine.

adb pull <database-file-on-device>

从 /tools 目录启动 sqlite3 工具,指定数据库文件:

Start the sqlite3 tool from the /tools directory, specifying the database file −

sqlite3 <database-file-on-host>

Platform tools

平台工具经过定制,支持最新 Android 平台的功能。

The platform tools are customized to support the features of the latest android platform.

通常在每次您安装新的 SDK 平台时,也会更新平台工具。平台工具的每次更新都向后兼容旧平台。

The platform tools are typically updated every time you install a new SDK platform. Each update of the platform tools is backward compatible with older platforms.

以下是此平台中的某些工具:

Some of the platform tools are listd below −

  1. Android Debug bridge (ADB)

  2. Android Interface definition language (AIDL)

  3. aapt, dexdump , and dex e.t.c