comandos más usuales: significado - gnomio · comandos más usuales: significado ... android debug...

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 even- numbered port for console connections and an odd-numbered port for adb connections. For example:

Upload: buithien

Post on 22-Sep-2018

252 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

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 even-numbered port for console connections and an odd-numbered port for adb connections. For example:

Page 2: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

Emulator 1, console: 5554 Emulator 1, adb: 5555 Emulator 2, console: 5556 Emulator 2, adb: 5557 ...

As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.

Once the server has set up connections to all emulator instances, you can use adb commands to control and access those instances. Because the server manages connections to emulator/device instances and handles commands from multiple adb clients, you can control any emulator/device instance from any client (or from a script).

• 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, 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).

En este ejemplo el primer dispositivo ya está operativo, pero el segundo está arrancando:

Al cabo de unos segundos, el segundo dispositivo termina de arrancar y ya está operativo:

• Mostrar el estado del dispositivo>adb get-state

Page 3: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

nota: el comando 'adb get-state' muestra el estado por consola ('unknown' la primera vez, 'device' la segunda vez) y finaliza, 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, se lanzó justo después de lanzar 'emultator @instancia-dispositivo', asi que el emulador estaba terminando de implementar la instancia de dispositivo, asi que inicialmente el demonio adb aún no estaba operativo ('State: unknown); unos segundos después el demonio adb está operativo ('State: device'). La ventana está 'bloqueda' recibiendo la información de estado del demonio adb, asi que para desbloquear la ventana, se pulsa 'ctrl+C'.

• 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, 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

Page 4: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

• Mostrar número de serie del dispositivo>adb get-serialno

nota: En el caso de que haya varias instancias de dispositivo activas, es útil conocer el nº de serie para conectar el cliente adb con el demonio adb del dispositivo deseado (adb -s nº-serie resto-opciones-adb). Por ejemplo: adb -s emulator-5554 shell stop.

•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. Al arrancar el cliente adb (comando adb), este comprueba que exista un servidor adb, y si no está, lo lanza; en todo caso siempre se puede lanzar el servidor expresamente (adb start-server).

• Parar el servidor adb

>adb kill-server

• Instalar una aplicación (paquete '.apk') en un dispositivo (si hay solo uno, no se indica nada)

>adb install ruta\paquete.apk

nota: el paquete se instala en el directorio /data/app/ del sistema de archivos del dispositivo:

Page 5: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

• Desinstalar una aplicación (paquete '.apk') en un dispositivo (si hay solo uno, no se indica nada)

>adb uninstall paquete.apk

• Lanzar una consola remota del dispositivoadb provides an ash shell that you can use to run a variety of commands on an emulator or device. The command binaries are stored in the file system of the emulator or device, in this location: /system/bin/

>adb shellWhen you are ready to exit the remote shell, use CTRL+D or exit to end the shell session.

Page 6: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

>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]

Page 7: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

•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

Page 8: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

>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; si se cierra esta consola (o se pulsa 'ctrl+C') se cerrará también el emulador. Una solución es abrir una segunda consola y utilizarla para lanzar nuevos comandos, dejando la anterior para visualizar el contenido del registro.

Redirecting Log Output to a file

>adb logcat -f fichero.txt ...resto

Filtering Log Output

To reduce the log output to a manageable level, 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.

A filter expression follows this format tag:priority ..., where tag indicates the tag of interest and priority indicates the minimum level of priority to report for that tag. Messages for that tag at or above the specified priority are written to the log. You can supply any number of tag:priority specifications in a single filter expression. The series of specifications is whitespace-delimited. The default output is to show all log messages with the Info priority (*:I).

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", at priority "Verbose" or above, and all log messages with tag "LifeCycleActivity", with priority "Info" or above. The final element in the above expression, *:S, sets the priority level for all tags to "silent", thus ensuring only log messages with "ActivityManager" and "LifeCycleActivity" are displayed. 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.

The following filter expression displays all log messages with priority level "warning" and higher, on all tags:

>adb logcat *:W

If you're running logcat from your development computer (versus running it on a remote adb

Page 9: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

shell), 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, if you are running logcat from a remote shell or using adb shell logcat.

Controlling Log Output Format

Log messages contain a number of metadata fields, in addition to the tag and priority. You can modify the output format for messages so that they display a specific metadata field. To do so, you use the -v option and specify one of the supported output formats listed below.

•brief — Display priority/tag and the PID of process issuing the message (the default format).•process — Display PID only.•tag — Display the priority/tag only. •raw — Display the raw log message, with no other metadata fields.•time — Display the date, invocation time, priority/tag, and PID of the process issuing the message.•threadtime — Display the date, invocation time, priority, tag, and the PID and TID of the thread issuing the message.•long — Display all metadata fields and separate messages with a blank lines. When starting 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.

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, and not all of the log messages are sent to the default circular buffer. To see additional log messages, you can start

Page 10: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

logcat with the -b option, to request viewing of an alternate circular buffer. 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. •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, the Android system sends stdout and stderr (System.out and System.err) output to /dev/null. In processes that run the Dalvik VM, you can have the system write a copy of the output to the log file. In this case, the system writes the messages to the log using the log tags stdout and stderr, both with priority I.

To route the output in this way, 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.redirect-stdio true>adb shell start

The system retains this setting until you terminate the emulator/device instance. To use the setting as a default on the emulator/device instance, you can add an entry to /data/local.prop on the device.

emulator

• Arrancar el emulador con una instancia de dispositivo:

1º) Averiguamos la lista de instancias de dispositivos ya creadas:

>android list avd

Page 11: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

2º) Invocamos al emulador para que cargue la instancia deseada:

>emulator @nombre-instancia

Eclipse: menú Window>Show View...>Devices

Page 12: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar

android

• Listar plataformas disponibles>android list target

• Listar dispositivos virtuales disponibles

>android list avd

• Lanzar AVD Manager

>android avd

Page 13: Comandos más usuales: Significado - Gnomio · Comandos más usuales: Significado ... Android Debug Bridge ... Una solución es abrir una segunda consola y utilizarla para lanzar