You are on page 1of 13

Comandos más usuales

:

Significado

android list avd

Listar las instancias de dispositivo existentes

emulator @nombreDispositivo

Lanzar el emulador con una instancia de disp.

abd wait-for-device

Bloquear la consola hasta que el disp. esté listo

adb get-serialno

Obtener el nº serie de los dispositivos lanzados

adb -s nºserie ...resto de opciones

Ejecuta cualquier comando adb sobre el
dispositivo indicado (en caso de que tengamos
varios dispositivos activos)

adb install [ruta en ordenador]paquete.apk

Instala un paquete en el dispositivo

adb shell

Abre una consola remota del dispositivo

adb logcat -v raw TAG:I *:S

Para ver el registro, solo las etiquetas deseadas

adb devices

Para averiguar si el demonio adb del dispositivo
responde al cliente adb (debería mostrarse el
estado 'device'; si el estado es 'unknown' hemos
perdido contacto con el dispositivo)

adb kill-server
adb start-server

Matar el servidor adb e iniciarlo de nuevo, con
la esperanza de poder contactar de nuevo con el
demonio adb del dispositivo.

adb
Android Device Bridge:
<sdk>/platform-tools/adb
<sdk>\docs\guide\developing\tools\adb.html
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an
emulator instance or connected Android-powered device. It is a client-server program that includes
three components:
•A client, which runs on your development machine. You can invoke a client from a shell by issuing
an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
•A server, which runs as a background process on your development machine. The server manages
communication between the client and the adb daemon running on an emulator or device.
•A daemon, which runs as a background process on each emulator or device instance.
When you start an adb client, the client first checks whether there is an adb server process already
running. If there isn't, it starts the server process. When the server starts, it binds to local TCP port
5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate
with the adb server.
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 evennumbered port for console connections and an odd-numbered port for adb connections. For
example:

• Mostrar los nombres de emuladores de dispositivos ya arrancados y su estado >adb devices -estado: device significa que ya está funcionando el demonio asociado al programa emulador -estado: offline significa que. aunque ya esté funcionando el programa emulador. the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554. Because the server manages connections to emulator/device instances and handles commands from multiple adb clients. En este ejemplo el primer dispositivo ya está operativo. console: 5556 Emulator 2. el segundo dispositivo termina de arrancar y ya está operativo: • Mostrar el estado del dispositivo >adb get-state . you can use adb commands to control and access those instances. Once the server has set up connections to all emulator instances. console: 5554 Emulator 1.. adb: 5557 . adb: 5555 Emulator 2.. el servidor adb asociado a ese emulador aún no ha arrancado nota: si se inició el emulador (emulator @instancia-dispositivo) y adb devices no detecta ninguna instancia activa. matar el servidor adb (adb kill-server) y volverlo a crear (adb start-server).Emulator 1. As shown. you can control any emulator/device instance from any client (or from a script). pero el segundo está arrancando: Al cabo de unos segundos.

se pulsa 'ctrl+C'. asi que para desbloquear la ventana. se lanzó justo después de lanzar 'emultator @instancia-dispositivo'. quedando bloqueada la consola: la consola solo se desbloquea después de que el emulador haya terminado de lanzar la instancia de dispositivo: nota: es útil para saber cuando ha terminado de completarse el arranque del dispositivo . asi que el emulador estaba terminando de implementar la instancia de dispositivo. • Bloquear el cliente adb hasta que el dispositivo esté on-line >adb wait-for-device se lanza una instancia del emulador y a continuación se lanza el comando adb wait-for-device. La ventana está 'bloqueda' recibiendo la información de estado del demonio adb. asi que vuelve a mostrarse el prompt del sistema operativo ('C:\Users\migue>'). • Mostrar ventana continuamente alimentada con estado del dispositivo (ctrl+C para 'salir' de la ventana) >adb status-window nota: El comando 'adb status-window' que se muestra en la imagen. 'device' la segunda vez) y finaliza.nota: el comando 'adb get-state' muestra el estado por consola ('unknown' la primera vez. asi que inicialmente el demonio adb aún no estaba operativo ('State: unknown). unos segundos después el demonio adb está operativo ('State: device').

es útil conocer el nº de serie para conectar el cliente adb con el demonio adb del dispositivo deseado (adb -s nº-serie restoopciones-adb). Por ejemplo: adb -s emulator-5554 shell stop. y si no está.apk') en un dispositivo (si hay solo uno. no se indica nada) >adb install ruta\paquete.• Mostrar número de serie del dispositivo >adb get-serialno nota: En el caso de que haya varias instancias de dispositivo activas.apk nota: el paquete se instala en el directorio /data/app/ del sistema de archivos del dispositivo: . este comprueba que exista un servidor adb. lo lanza. Al arrancar el cliente adb (comando adb). •Arrancar el servidor adb >adb start-server nota: Al arrancar el emulador con una instancia (emulador @instancia-dispositivo) se arranca un adb daemon sobre esa instancia. • Parar el servidor adb >adb kill-server • Instalar una aplicación (paquete '. en todo caso siempre se puede lanzar el servidor expresamente (adb start-server).

.apk • Lanzar una consola remota del dispositivo adb provides an ash shell that you can use to run a variety of commands on an emulator or device. in this location: /system/bin/ >adb shell When you are ready to exit the remote shell. no se indica nada) >adb uninstall paquete.• Desinstalar una aplicación (paquete '. use CTRL+D or exit to end the shell session.apk') en un dispositivo (si hay solo uno. The command binaries are stored in the file system of the emulator or device.

>adb shell comando • Copiar un archivo o directorio del ordenador al dispositivo >adb push local remoto • Copiar un archivo o directorio del dispositivo al ordenador >adb pull remoto [local] .

•Copiar un directorio del ordenador al dispositivo solo si ha cambiado >adb sync [directorio_local] •Parar el dispositivo >adb shell stop Para detener una instancia de dispositivo concreta: •(Re)arrancar el dispositivo >adb shell start Para (re)arrancar una instancia de dispositivo concreta: • Mostrar por consola el contenido del registro de un dispositivo .

. where tag indicates the tag of interest and priority indicates the minimum level of priority to report for that tag.resto Filtering Log Output To reduce the log output to a manageable level. with priority "Info" or above. thus ensuring only log messages with "ActivityManager" and "LifeCycleActivity" are displayed. si se cierra esta consola (o se pulsa 'ctrl+C') se cerrará también el emulador.. The default output is to show all log messages with the Info priority (*:I). The following filter expression displays all log messages with priority level "warning" and higher.>adb logcat (to view log output in your development computer) >adb shell #logcat (from a remote adb shell in an emulator/device instance) nota: La consola que lanza el comando adb logcat se queda 'bloqueada' recibiendo información de registro desde el dispositivo. Using *:S is an excellent way to ensure that log output is restricted to the filters that you have explicitly specified — it lets your filters serve as a "whitelist" for log output. Messages for that tag at or above the specified priority are written to the log. at priority "Verbose" or above.. Redirecting Log Output to a file >adb logcat -f fichero. For example: >adb logcat ActivityManager:V LifeCycleActivity:I *:S Here's an example of a filter expression that suppresses all log messages except those with the tag "ActivityManager". sets the priority level for all tags to "silent". and all log messages with tag "LifeCycleActivity".. You can supply any number of tag:priority specifications in a single filter expression. The series of specifications is whitespace-delimited. The final element in the above expression. you can restrict log output using filter expressions. Filter expressions let you indicate to the system the tags-priority combinations that you are interested in — the system suppresses other messages for the specified tags.txt . dejando la anterior para visualizar el contenido del registro.. *:S. on all tags: >adb logcat *:W If you're running logcat from your development computer (versus running it on a remote adb . Una solución es abrir una segunda consola y utilizarla para lanzar nuevos comandos. A filter expression follows this format tag:priority .

with no other metadata fields. •time — Display the date. you can start . you can also set a default filter expression by exporting a value for the environment variable ANDROID_LOG_TAGS: export ANDROID_LOG_TAGS="ActivityManager:V LifeCicleActivity:I *:S" Note that ANDROID_LOG_TAGS filter is not exported to the emulator/device instance. You can modify the output format for messages so that they display a specific metadata field. To see additional log messages. and not all of the log messages are sent to the default circular buffer. if you are running logcat from a remote shell or using adb shell logcat. you can specify the output format you want by using the -v option: [adb] logcat [-v <format>] Here's an example that shows how to generate messages in thread output format: adb logcat -v thread Note that you can only specify one output format with the -v option. you use the -v option and specify one of the supported output formats listed below. tag. •long — Display all metadata fields and separate messages with a blank lines. invocation time. invocation time. •process — Display PID only. •threadtime — Display the date. For example: >adb logcat -v process LifeCycleActivity:I *:S >adb logcat -v raw LifeCycleActivity:I *:S Viewing Alternative Log Buffers The Android logging system keeps multiple circular buffers for log messages. priority. •brief — Display priority/tag and the PID of process issuing the message (the default format). •tag — Display the priority/tag only.shell). Controlling Log Output Format Log messages contain a number of metadata fields. To do so. and the PID and TID of the thread issuing the message. and PID of the process issuing the message. •raw — Display the raw log message. in addition to the tag and priority. When starting logcat. priority/tag.

you stop a running emulator/device instance and then use the shell command setprop to enable the redirection of output. Here's how you do it: >adb shell stop >adb shell setprop log. In this case. you can have the system write a copy of the output to the log file. In processes that run the Dalvik VM. the Android system sends stdout and stderr (System.logcat with the -b option.err) output to /dev/null. emulator • Arrancar el emulador con una instancia de dispositivo: 1º) Averiguamos la lista de instancias de dispositivos ya creadas: >android list avd . •main — View the main log buffer (default) The usage of the -b option is: [adb] logcat [-b <buffer>] Here's an example of how to view a log buffer containing radio and telephony messages: adb logcat -b radio Viewing stdout and stderr By default.redirect-stdio true >adb shell start The system retains this setting until you terminate the emulator/device instance.prop on the device. You can view any of these alternate buffers: •radio — View the buffer that contains radio/telephony related messages. •events — View the buffer containing events-related messages. to request viewing of an alternate circular buffer. you can add an entry to /data/local. both with priority I. To route the output in this way. the system writes the messages to the log using the log tags stdout and stderr. To use the setting as a default on the emulator/device instance.out and System.

.2º) Invocamos al emulador para que cargue la instancia deseada: >emulator @nombre-instancia Eclipse: menú Window>Show View.>Devices ..

android • Listar plataformas disponibles >android list target • Listar dispositivos virtuales disponibles >android list avd • Lanzar AVD Manager >android avd .