<p>The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports — an even-numbered port for console connections and an odd-numbered port for adb connections. For example: </p>
<li><code>[parm]... </code> — zero or more PPP/PPPD options, such as <code>defaultroute</code>, <code>local</code>, <code>notty</code>, etc.</li></ul>
<td>Prints the adb instance serial number string.</td>
<td rowspan="2">See <a href="#devicestatus">Querying for Emulator/Device Instances</a> for more information. </td>
</tr>
<tr>
<td><code>get-state</code></td>
<td>Prints the adb state of an emulator/device instance.</td>
</td>
</tr>
<tr>
<td><code>wait-for-device</code></td>
<td>Blocks execution until the device is online — that is, until the instance state is <code>device</code>.</td>
<td>You can prepend this command to other adb commands, in which case adb will wait until the emulator/device instance is connected before issuing the other commands. Here's an example:
Note that this command does <em>not</em> cause adb to wait until the entire system is fully booted. For that reason, you should not prepend it to other commands that require a fully booted system. As an example, the <code>install</code> requires the Android package manager, which is available only after the system is fully booted. A command such as
would issue the <code>install</code> command as soon as the emulator or device instance connected to the adb server, but before the Android system was fully booted, so it would result in an error. </td>
</tr>
<tr>
<td rowspan="2">Server</td>
<td><code>start-server</code></td>
<td>Checks whether the adb server process is running and starts it, if not.</td>
<td> </td>
</tr>
<tr>
<td><code>kill-server</code></td>
<td>Terminates the adb server process.</td>
<td> </td>
</tr>
<tr>
<td rowspan="2">Shell</td>
<td><code>shell</code></td>
<td>Starts a remote shell in the target emulator/device instance.</td>
<td rowspan="2">See <a href="#shellcommands">Issuing Shell Commands</a> for more information. </td>
<h2 id="devicestatus">Querying for Emulator/Device Instances</h2>
<p>Before issuing adb commands, it is helpful to know what emulator/device instances are connected to the adb server. You can generate a list of attached emulators/devices using the <code>devices</code> command: </p>
<pre class="no-pretty-print">adb devices</pre>
<p>In response, adb prints this status information for each instance:</p>
<ul>
<li>Serial number — A string created by adb to uniquely identify an emulator/device instance by its
console port number. The format of the serial number is <code><type>-<consolePort></code>.
Here's an example serial number: <code>emulator-5554</code></li>
<li>State — The connection state of the instance may be one of the following:
<ul>
<li><code>offline</code> — the instance is not connected to adb or is not responding.</li>
<li><code>device</code> — the instance is now connected to the adb server. Note that this state does not
imply that the Android system is fully booted and operational, since the instance connects to adb
while the system is still booting. However, after boot-up, this is the normal operational state of
an emulator/device instance.</li>
<li><code>no device</code> — there is no emulator/device connected.
</ul>
</li>
</ul>
<p>The output for each instance is formatted like this: </p>
<p>Note that, if you issue a command without specifying a target emulator/device instance
while multiple devices are available, adb generates an error.
<p>If you have multiple devices available (hardware or emulated), but only one is an emulator,
simply use the {@code -e} option to send commands to the emulator. Likewise if there's multiple
devices but only one hardware device attached, use the {@code -d} option to send commands to
the hardware device.
<h2 id="move">Installing an Application</h2>
<p>You can use adb to copy an application from your development computer and install it on an emulator/device instance. To do so, use the <code>install</code> command. With the command, you must specify the path to the .apk file that you want to install:</p>
<p>For more information about how to create an .apk file that you can install on an emulator/device
instance, see <a href="{@docRoot}tools/building/index.html">Building and Running</a></p>
<p>Note that, if you are using the Eclipse IDE and have the ADT plugin installed, you do not need to use adb (or aapt) directly to install your application on the emulator/device. Instead, the ADT plugin handles the packaging and installation of the application for you. </p>
<h2 id="forwardports">Forwarding Ports</h2>
<p>You can use the <code>forward</code> command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 6100 to emulator/device port 7100:</p>
<dd>You can directly specify a URI, package name, and component name when not qualified
by one of the above options. When an argument is unqualified, the tool assumes the argument
is a URI if it contains a ":" (colon); it assumes the argument is a component name if it
contains a "/" (forward-slash); otherwise it assumes the argument is a package name.
</dl>
</div><!-- end 'intents' -->
<script>
$(window).hashchange( function(){
if ((location.hash == "#IntentSpec") && !($("#IntentSpec a").hasClass("expanded"))) {
$("#IntentSpec a").click();
}
});
</script>
<h3 id="pm">Using package manager (pm)</h3>
<p>Within an adb shell, you can issue commands with the package manager ({@code pm}) tool to
perform actions and queries on application packages installed on the device. While in a shell,
the syntax is:</p>
<pre class="no-pretty-print">
pm <command>
</pre>
<p>You can also issue a package manager command directly from adb
without entering a remote shell. For example:</p>
<pre class="no-pretty-print">
adb shell pm uninstall com.example.MyApp
</pre>
<p class="table-caption"><strong>Table 3.</strong> Available package manager commands.</p>
<table>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
<tr>
<td><code>
list packages [options] <FILTER>
</code></td>
<td>Prints all packages, optionally only
those whose package name contains the text in {@code <FILTER>}. <p>Options:
<ul>
<li>{@code -f}: See their associated file.
<li>{@code -d}: Filter to only show disabled packages.
<li>{@code -e}: Filter to only show enabled packages.
<li>{@code -s}: Filter to only show system packages.
<li>{@code -3}: Filter to only show third party packages.
<li>{@code -i}: See the installer for the packages.
<li>{@code -u}: Also include uninstalled packages.
<li>{@code --user <USER_ID>}: The user space to query.
</ul>
</td>
</tr>
<tr>
<td><code>
list permission-groups
</code></td>
<td>Prints all known permission groups.
</td>
</tr>
<tr>
<td><code>
list permissions [options] <GROUP>
</code></td>
<td>Prints all known permissions, optionally only
those in {@code <GROUP>}. <p>Options:
<ul>
<li>{@code -g}: Organize by group.
<li>{@code -f}: Print all information.
<li>{@code -s}: Short summary.
<li>{@code -d}: Only list dangerous permissions.
<li>{@code -u}: List only the permissions users will see.
</ul>
</td>
</tr>
<tr>
<td><code>
list instrumentation
</code></td>
<td>List all test packages. <p>Options:
<ul>
<li>{@code -f}: List the APK file for the test package.
<li>{@code <TARGET_PACKAGE>}: List test packages for only this app.
</ul>
</td>
</tr>
<tr>
<td><code>
list features
</code></td>
<td>Prints all features of the system.
</td>
</tr>
<tr>
<td><code>
list libraries
</code></td>
<td>Prints all the libraries supported by the current device.
</td>
</tr>
<tr>
<td><code>
list users
</code></td>
<td>Prints all users on the system.
</td>
</tr>
<tr>
<td><code>
path <PACKAGE>
</code></td>
<td>Print the path to the APK of the given {@code <PACKAGE>}.
</td>
</tr>
<tr>
<td><code>
install [options] <PATH>
</code></td>
<td>Installs a package (specified by {@code <PATH>}) to the system. <p>Options:
<ul>
<li>{@code -l}: Install the package with forward lock.
<li>{@code -r}: Reinstall an exisiting app, keeping its data.
<li>{@code -t}: Allow test APKs to be installed.
<li>{@code -i <INSTALLER_PACKAGE_NAME>}: Specify the installer package name.
<li>{@code -s}: Install package on the shared mass storage (such as sdcard).
<li>{@code -f}: Install package on the internal system memory.
<li>{@code -d}: Allow version code downgrade.
</ul>
</td>
</tr>
<tr>
<td><code>
uninstall [options] <PACKAGE>
</code></td>
<td>Removes a package from the system. <p>Options:
<ul>
<li>{@code -k}: Keep the data and cache directories around after package removal.
</ul>
</td>
</tr>
<tr>
<td><code>
clear <PACKAGE>
</code></td>
<td>Deletes all data associated with a package.
</td>
</tr>
<tr>
<td><code>
enable <PACKAGE_OR_COMPONENT>
</code></td>
<td>Enable the given package or component (written as "package/class").
</td>
</tr>
<tr>
<td><code>
disable <PACKAGE_OR_COMPONENT>
</code></td>
<td>Disable the given package or component (written as "package/class").
</td>
</tr>
<tr>
<td style="white-space:nowrap"><code>
disable-user [options] <PACKAGE_OR_COMPONENT>
</code></td>
<td><p>Options:
<ul>
<li>{@code --user <USER_ID>}: The user to disable.
</ul>
</td>
</tr>
<tr>
<td><code>
grant <PACKAGE_PERMISSION>
</code></td>
<td>Grant permissions
to applications. Only optional permissions the application has
declared can be granted.
</td>
</tr>
<tr>
<td><code>
revoke <PACKAGE_PERMISSION>
</code></td>
<td>Revoke permissions
to applications. Only optional permissions the application has
declared can be revoked.
</td>
</tr>
<tr>
<td><code>
set-install-location <LOCATION>
</code></td>
<td>Changes the default install location. Location values:
<ul>
<li>{@code 0}: Auto—Let system decide the best location.
<li>{@code 1}: Internal—install on internal device storage.
<li>{@code 2}: External—install on external media.
</ul>
<p class="note"><strong>Note:</strong> This is only intended for debugging; using this can cause
applications to break and other undesireable behavior.</p>
</td>
</tr>
<tr>
<td><code>
get-install-location
</code></td>
<td>Returns the current install location. Return values:
<ul>
<li>{@code 0 [auto]}: Lets system decide the best location
<li>{@code 1 [internal]}: Installs on internal device storage
<li>{@code 2 [external]}: Installs on external media
<a href="http://www.sqlite.org/sqlite.html">sqlite3</a> command-line program to
manage SQLite databases created by Android applications. The
<code>sqlite3</code> tool includes many useful commands, such as
<code>.dump</code> to print out the contents of a table and
<code>.schema</code> to print the SQL CREATE statement for an existing table.
The tool also gives you the ability to execute SQLite commands on the fly.</p>
<p>To use <code>sqlite3</code>, enter a remote shell on the emulator instance, as described above, then invoke the tool using the <code>sqlite3</code> command. Optionally, when invoking <code>sqlite3</code> you can specify the full path to the database you want to explore. Emulator/device instances store SQLite3 databases in the folder <code><span chatdir="1"><span chatindex="259474B4B070F261">/data/data/<em><package_name></em>/databases</span></span>/</code>. </p>
<p>Once you've invoked <code>sqlite3</code>, you can issue <code>sqlite3</code> commands in the shell. To exit and return to the adb remote shell, use <code>exit</code> or <code>CTRL+D</code>.
<p>The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the <code>logcat</code> command.</p>
<p>You can use the <code>logcat</code> command to view and follow the contents of the system's log buffers. The general usage is:</p>
<p>You can use the <code>logcat</code> command from your development computer or from a remote adb shell in an emulator/device instance. To view log output in your development computer, you use</p>
<p>See <a href="{@docRoot}tools/debugging/debugging-log.html">Reading and Writing Logs</a> for complete information about logcat commend options and filter specifications.</p>
<p>In some cases, you might need to terminate the adb server process and then restart it. For example, if adb does not respond to a command, you can terminate the server and restart it and that may resolve the problem. </p>