madb

command module
v2.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2016 License: BSD-3-Clause Imports: 19 Imported by: 0

README

Madb: Multi-device Android Debug Bridge

Latest Release [![Build Status][travis-image]][travis-link] Coverage Status Online Documentation Slides

Madb is a command line tool that wraps Android Debug Bridge (adb) and provides various features for controlling multiple Android devices concurrently. This slide deck illustrates how madb works with multiple devices.

This tool is part of the Vanadium effort to build a framework and a set of development tools to enable and ease the creation of multi-device user interfaces and apps.

Madb releases are versioned according to Semantic Versioning 2.0.0.

Requirements

  • OS
  • Linux (64bit)
  • Mac OS X (64bit)
  • Windows will be supported soon
  • Tools
  • ADB: must be installed and accessible from PATH. ADB comes with the Android SDK.
  • (Optional) Flutter: needed for using Flutter project specific features.

Installing madb

Using Homebrew

On Mac OS X, madb can be installed using Homebrew.

$ brew tap baku-io/baku
$ brew install madb

To upgrade madb to the most recent version,

$ brew update
$ brew upgrade madb

Downloading the Latest Release

The latest release of madb can be downloaded from the Releases Page.

Download the binary for your platform, and extract it to your desired location. Make sure to add the location in your PATH environment variable to use madb from anywhere.

Using Go Get Command

If you have Go command line tool installed, you can also use the go get command to get the most recent version of madb:

$ go get github.com/vanadium/madb

This will install the tool under <your GOPATH>/bin/madb. To upgrade the tool to the most recent version:

$ go get -u github.com/vanadium/madb

NOTE: go get will always get the latest development version (i.e. the current version in the master branch), not the stable release.

Getting Started

This section introduces the most notable features of madb. To see the complete list of features and their options, please use madb help or madb help <topic> in your command line, or refer to our Online Documentation.

Also, please refer to this slide deck, which illustrates how madb works with multiple devices.

Running an Android App on All Devices

If your have an Android application project using the Android plugin for Gradle as the build system (see if you have build.gradle file in your project directory), you can type the following command from the project directory to build, install, and launch your app on all connected devices in parallel:

[From the project directory]
$ madb start

Compare this with the following equivalent adb command:

[For each device]
$ adb -s <device_serial> shell am start -n <app ID>/<activity name>
...

The madb start command is more convenient in a few major ways.

First, with a single madb start command, it launches the app on all devices and emulators. With only adb, you would have to manually issue the same command with different device serials, or use a loop construct in a shell script to get the same behavior, for example.

Next, madb start does not require any additional parameters. Internally, madb reads the Gradle build scripts and the AndroidManifest.xml files in the current directory, and automatically extracts the application ID and main activity name to install and launch the correct app on all devices.

In case your build script contains some APK split configurations, madb will install the best matching APK for each device, depending on the device supported ABIs and the screen density.

Also, the adb console outputs from each device is prefixed with the name of the device, line by line. The following example output from madb start demonstrates this.

[MyTablet]      7404 KB/s (21315847 bytes in 2.811s)
[MyTablet]              pkg: /data/local/tmp/app-universal-debug.apk
[MyPhone]       6270 KB/s (21315847 bytes in 3.319s)
[MyPhone]               pkg: /data/local/tmp/app-universal-debug.apk
[MyPhone]       Success
[MyPhone]       Stopping: com.yourcompany.yourapp
[MyPhone]       Starting: Intent { cmp=com.yourcompany.yourapp/.YourMainActivity }
[MyTablet]      Success
[MyTablet]      Stopping: com.yourcompany.yourapp
[MyTablet]      Starting: Intent { cmp=com.yourcompany.yourapp/.YourMainActivity }
$ _

Here, the names MyPhone and MyTablet are the device nicknames given using madb name command. If these nicknames are not set, madb will show the corresponding device serial number instead. When something goes wrong with one of the devices, then you can see which of the available devices generated the error by reading the prefixed device name.

If you want to skip the build step and just restart the app on all devices, you can use the -build=false flag:

$ madb start -build=false

Running Arbitrary ADB Commands on All Devices

You can execute any adb commands on all devices in parallel using madb exec command. For example, imagine you want to see the current time from all devices to determine if there clocks are significantly skewed. You can use the following madb command to check this:

$ madb exec shell date
[MyTablet]      Fri Apr 15 14:08:07 PDT 2016
[MyPhone]       Fri Apr 15 14:08:03 PDT 2016
$ _

As a special case, madb exec shell <args...> command can be shortened as madb shell <args...>. Therefore, the above command can be shortened as:

$ madb shell date

NOTE: Launching an interactive shell (i.e. adb shell without arguments) on all devices is not supported, and the behavior of madb exec shell or madb shell without any arguments is undefined. Always provide a specific shell command to execute.

If you want to copy a configuration file on your local computer to all devices, you can use madb exec to issue adb push command on all devices as following:

$ madb exec push your.config /sdcard/
[MyTablet]      92 KB/s (4087 bytes in 0.043s)
[MyPhone]       87 KB/s (4087 bytes in 0.045s)
$ _

Also, you can see the live interleaving logcat messages coming from all devices by:

$ madb exec logcat

Giving Nicknames to Devices

As shown in the above examples, you can give human-friendly nicknames to your devices. Once you give a nickname to a device, that nickname is used as the console output prefix instead of its device serial number. To give a nickname, you can use madb name set command.

$ madb name set <device_serial> <nickname>

You can see the serial numbers of your devices with adb devices -l command.

$ adb devices -l
List of devices attached
01023f5e2fd2acab       device usb:3-5.3 product:bullhead model:Nexus_5X device:bullhead
HT4BVWV00000           device usb:3-5.4.2 product:volantisg model:Nexus_9 device:flounder_lte

$ _

In this output, 01023f5e2fd2acab and HT4BVWV00000 are the device serials. To give MyPhone as the nickname of the Nexus 5X phone with serial 01023f5e2fd2acab,

$ madb name set 01023f5e2fd2acab MyPhone

Similarly, you can give MyTablet as the nickname of the second device.

$ madb name set HT4BVWV00000 MyTablet

To unset a given nickname, you can use madb name unset.

$ madb name unset <device serial OR nickname>

For the purpose of displaying the nicknames as the console output prefixes, the mapping between device serials and nicknames is kept 1:1. That is, there can be only one nickname for any given device serial, and a nickname always resolves to a single device serial.

Specifying Devices

There can be situations where a certain adb command should be run only on a subset of all available devices. madb provides a few flags for these situations.

  • -d: Restrict the command to only run on real devices.
  • -e: Restrict the command to only run on emulators.
  • -n=<device1,device2,...>: Comma-separated device serials, qualifiers, device indices (e.g., @1, @2), or nicknames (set by madb name). Command will run only on specified devices.

For example, to launch your app only on emulators:

$ madb -e start

To see the logcat messages from Alice and Bob devices and not from others:

$ madb -n=Alice,Bob exec logcat

Keyword Expansion

There are a few pre-defined keywords that can be expanded within an argument of madb exec command.

  • {{index}}: the index of the current device, starting from 1.
  • {{name}}: the nickname of the current device, or the serial number if a nickname is not set.
  • {{serial}}: the serial number of the current device.

Suppose there are three named devices: Alice, Bob, and Carol. You might want to push some configuration files that are slightly different for each device before running your app. For example, you can:

  • copy local Alice.config file to /sdcard/yourapp.config on device Alice
  • copy local Bob.config file to /sdcard/yourapp.config on device Bob
  • copy local Carol.config file to /sdcard/yourapp.config on device Carol

with the following one-line madb command.

$ madb exec push {{name}}.config /sdcard/yourapp.config

[travis-image]: https://img.shields.io/travis/vanadium/madb/master.svg?style=flat-square) [travis-link]: https://travis-ci.org/vanadium/madb

Documentation

Overview

Multi-device Android Debug Bridge

The madb command wraps Android Debug Bridge (adb) command line tool and provides various features for controlling multiple Android devices concurrently.

Usage:

madb [flags] <command>

The madb commands are:

clear-data  Clear your app data from all devices
exec        Run the provided adb command on all devices and emulators
            concurrently
extern      Run the provided external command for all devices
group       Manage device groups
install     Install your app on all devices
name        Manage device nicknames
resolve     Resolve device specifiers into device serials
shell       Run the provided adb shell command on all devices and emulators
            concurrently
start       Launch your app on all devices
stop        Stop your app on all devices
uninstall   Uninstall your app from all devices
user        Manage default user settings for each device
version     Print the madb version number
help        Display help for commands or topics

The madb flags are:

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

The global flags are:

-metadata=<just specify -metadata to activate>
  Displays metadata for the program and exits.
-time=false
  Dump timing information to stderr before exiting the program.

Madb clear-data - Clear your app data from all devices

Clears your app data from all devices.

To specify which user's data should be cleared, use 'madb user set' command to set the default user ID for that device. (See 'madb help user' for more details.)

Usage:

madb clear-data [flags] [<application_id>]

<application_id> is usually the package name where the activities are defined. (See: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename)

If the application ID is not specified, madb automatically determines which app to be cleared, based on the build scripts found in the current working directory.

If the working directory contains a Gradle Android project (i.e., has "build.gradle"), run a small Gradle script to extract the application ID. In this case, the extracted ID is cached, so that "madb clear-data" can be repeated without even running the Gradle script again. The ID can be re-extracted by clearing the cache by providing "-clear-cache" flag.

The madb clear-data flags are:

-clear-cache=false
  Clear the cache and re-extract the variant properties such as the application
  ID and the main activity name. Only takes effect when no arguments are
  provided.
-module=
  Specify which application module to use, when the current directory is the
  top level Gradle project containing multiple sub-modules. When not specified,
  the first available application module is used. Only takes effect when no
  arguments are provided.
-variant=
  Specify which build variant to use. When not specified, the first available
  build variant is used. Only takes effect when no arguments are provided.

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb exec - Run the provided adb command on all devices and emulators concurrently

Runs the provided adb command on all devices and emulators concurrently.

For example, the following line:

madb exec push ./foo.txt /sdcard/foo.txt

copies the ./foo.txt file to /sdcard/foo.txt for all the currently connected devices.

There are a few pre-defined keywords that can be expanded within an argument.

"{{index}}"  : the index of the current device, starting from 1.
"{{name}}"   : the nickname of the current device, or the serial number if a nickname is not set.
"{{serial}}" : the serial number of the current device.

For example, the following line:

madb exec -n=Alice,Bob push ./{{name}}.txt /sdcard/{{name}}.txt

copies the ./Alice.txt file to the device named Alice, and ./Bob.txt to the device named Bob. Note that you should type in "{{name}}" as-is, with the opening/closing curly braces, similar to when you're using a template library such as mustache.

To see the list of available adb commands, type 'adb help'.

Usage:

madb exec [flags] <command>

<command> is a normal adb command, which will be executed on all devices and emulators.

The madb exec flags are:

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb extern - Run the provided external command for all devices

Runs the provided external command for all devices and emulators concurrently.

For each available device, this command will spawn a sub-shell with the ANDROID_SERIAL environmental variable set to the target device serial, and then will run the provided external command.

There are a few pre-defined keywords that can be expanded within an argument.

"{{index}}"  : the index of the current device, starting from 1.
"{{name}}"   : the nickname of the current device, or the serial number if a nickname is not set.
"{{serial}}" : the serial number of the current device.

For example, the following line:

madb extern echo I am {{name}}, and my serial number is {{serial}}.

prints out the name and serial pairs for each device.

Note that you should type in "{{name}}" as-is, with the opening/closing curly braces, similar to when you're using a template library such as mustache.

This command is intended to be used with external commands that are designed to work with only a single device at a time (e.g. gomobile, flutter).

Usage:

madb extern [flags] <external_command>

<external_command> is an external shell command to run for all devices and emulators.

The madb extern flags are:

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb group - Manage device groups

Manages device groups, each of which can have one or more device members. The device groups can be used for specifying the target devices of other madb commands.

Usage:

madb group [flags] <command>

The madb group commands are:

add         Add members to a device group
clear-all   Clear all the existing device groups
delete      Delete an existing device group
list        List all the existing device groups
remove      Remove members from a device group
rename      Rename an existing device group

Madb group add - Add members to a device group

Adds members to a device group. This command also creates the group, if the group does not exist yet. The device group can be used when specifying devices in any madb commands.

When creating a new device group with this command, the provided name must not conflict with an existing device nickname (see: madb help name set).

A group can contain another device group, in which case all the members of the other group will also be considered as members of the current group.

Usage:

madb group add [flags] <group_name> <member1> [<member2> ...]

<group_name> is an alpha-numeric string with no special characters or spaces. This name must not be an existing device nickname.

<member> is a member specifier, which can be one of device serial, qualifier, device index (e.g., '@1', '@2'), device nickname, or another device group.

Madb group clear-all - Clear all the existing device groups

Clears all the existing device groups.

Usage:

madb group clear-all [flags]

Madb group delete - Delete an existing device group

Deletes an existing device group.

Usage:

madb group delete [flags] <group_name1> [<group_name2> ...]

<group_name> the name of an existing device group. You can specify more than one group names.

Madb group list - List all the existing device groups

Lists the name and members of all the existing device groups.

Usage:

madb group list [flags]

Madb group remove - Remove members from a device group

Removes members from an existing device group. If there are no remaining members after that, the group gets deleted.

Usage:

madb group remove [flags] <group_name> <member1> [<member2> ...]

<group_name> is an alpha-numeric string with no special characters or spaces. This name must be an existing device group name.

<member> is a member specifier, which can be one of device serial, qualifier, device index (e.g., '@1', '@2'), device nickname, or another device group.

Madb group rename - Rename an existing device group

Renames an existing device group.

Usage:

madb group rename [flags] <old_name> <new_name>

<old_name> is the name of an existing device group.

<new_name> is the new name for the existing group. This must be an alpha-numeric string with no special characters or spaces, and must not conflict with another existing device or group name.

Madb install - Install your app on all devices

Installs your app on all devices.

If the working directory contains a Gradle Android project (i.e., has "build.gradle"), this command will first run a small Gradle script to extract the variant properties, which will be used to find the best matching .apk for each device. These extracted properties are cached, and "madb install" can be repeated without running this Gradle script again. The properties can be re-extracted by clearing the cache by providing "-clear-cache" flag.

Once the variant properties are extracted, the best matching .apk for each device will be installed in parallel.

This command is similar to running "gradlew :<moduleName>:<variantName>Install", but "madb install" is more flexible: 1) you can install the app to a subset of the devices, and 2) the app is installed concurrently, which saves a lot of time.

If the working directory contains a Flutter project (i.e., has "flutter.yaml"), this command will run "flutter install --device-id <device serial>" for all devices.

To install your app for a specific user on a particular device, use 'madb user set' command to set the default user ID for that device. (See 'madb help user' for more details.)

To install a specific .apk file to all devices, use "madb exec install <path_to_apk>" instead.

Usage:

madb install [flags]

The madb install flags are:

-build=true
  Build the target app variant before installing or running the app.
-clear-cache=false
  Clear the cache and re-extract the variant properties such as the application
  ID and the main activity name. Only takes effect when no arguments are
  provided.
-module=
  Specify which application module to use, when the current directory is the
  top level Gradle project containing multiple sub-modules. When not specified,
  the first available application module is used. Only takes effect when no
  arguments are provided.
-variant=
  Specify which build variant to use. When not specified, the first available
  build variant is used. Only takes effect when no arguments are provided.

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb name - Manage device nicknames

Manages device nicknames, which are meant to be more human-friendly compared to the device serials provided by adb tool.

Usage:

madb name [flags] <command>

The madb name commands are:

set         Set a nickname to be used in place of the device serial.
unset       Unset a nickname set by the 'madb name set' command.
list        List all the existing nicknames.
clear-all   Clear all the existing nicknames.

Madb name set

Sets a human-friendly nickname that can be used when specifying the device in any madb commands.

The device serial can be obtained using the 'adb devices -l' command. For example, consider the following example output:

HT4BVWV00023           device usb:3-3.4.2 product:volantisg model:Nexus_9 device:flounder_lte

The first value, 'HT4BVWV00023', is the device serial. To assign a nickname for this device, run the following command:

madb name set HT4BVWV00023 MyTablet

and it will assign the 'MyTablet' nickname to the device serial 'HT4BVWV00023'. The alternative device specifiers (e.g., 'usb:3-3.4.2', 'product:volantisg') can also have nicknames.

When a nickname is set for a device serial, the nickname can be used to specify the device within madb commands.

There can only be one nickname for a device serial. When the 'madb name set' command is invoked with a device serial with an already assigned nickname, the old one will be replaced with the newly provided one.

Usage:

madb name set [flags] <device_serial> <nickname>

<device_serial> is a device serial (e.g., 'HT4BVWV00023') or an alternative device qualifier (e.g., 'usb:3-3.4.2') obtained from 'adb devices -l' command <nickname> is an alpha-numeric string with no special characters or spaces.

Madb name unset

Unsets a nickname assigned by the 'madb name set' command. Either the device serial or the assigned nickname can be specified to remove the mapping.

Usage:

madb name unset [flags] <device_serial | nickname>

There should be only one argument, which is either the device serial or the nickname.

Madb name list

Lists all the currently stored nicknames of device serials.

Usage:

madb name list [flags]

Madb name clear-all

Clears all the currently stored nicknames of device serials.

Usage:

madb name clear-all [flags]

Madb resolve - Resolve device specifiers into device serials

Resolves the provided device specifiers and prints out their device serials, each in a separate line. This command only displays the unique serials of the devices that are currently available.

This command can be useful when you want to use the device nicknames and groups defined by madb in other command line tools. For example, to run a flutter app on "MyTablet" device, you can use the following command (in Bash):

flutter run --device $(madb resolve MyTablet)

Usage:

madb resolve [flags] <specifier1> [<specifier2> ...]

<specifier> can be anything that is accepted in the '-n' flag (see 'madb help'). It can be a device serial, qualifier, index, nickname, or a device group name.

Madb shell - Run the provided adb shell command on all devices and emulators concurrently

Runs the provided adb shell command on all devices and emulators concurrently.

This command is a shorthand syntax for 'madb exec shell <command...>'. See 'madb help exec' for more details.

Usage:

madb shell [flags] <command>

<command> is a normal adb shell command, which will be executed on all devices and emulators.

The madb shell flags are:

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb start - Launch your app on all devices

Launches your app on all devices.

In most cases, running "madb start" from an Android Gradle project directory will do the right thing for you. "madb start" will build the project first. After the project build is completed, this command will install the best matching .apk for each device, only if one or more of the following conditions are met:

  • the app is not found on the device
  • the installed app is outdated (determined by comparing the last update time of the installed app and the last modification time of the local .apk file)
  • "-force-install" flag is set

If you would like to run the same version of the app repeatedly (e.g., for QA testing), you can explicitly turn off the build flag by providing "-build=false" to skip the build step.

To run your app as a specific user on a particular device, use 'madb user set' command to set the default user ID for that device. (See 'madb help user' for more details.)

Usage:

madb start [flags] [<application_id> <activity_name>]

<application_id> is usually the package name where the activities are defined. (See: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename)

<activity_name> is the Java class name for the activity you want to launch. If the package name of the activity is different from the application ID, the activity name must be a fully-qualified name (e.g., com.yourcompany.yourapp.MainActivity).

If either <application_id> or <activity_name> is provided, the other must be provided as well.

If no arguments are specified, madb automatically determines which app to launch, based on the build scripts found in the current working directory.

1) If the working directory contains a Flutter project (i.e., has "flutter.yaml"), this command will run "flutter start --device-id <device serial>" for all the specified devices.

2) If the working directory contains a Gradle Android project (i.e., has "build.gradle"), this command will run a small Gradle script to extract the application ID and the main activity name. In this case, the extracted IDs are cached, so that "madb start" can be repeated without even running the Gradle script again. The IDs can be re-extracted by clearing the cache by providing "-clear-cache" flag.

The madb start flags are:

-build=true
  Build the target app variant before installing or running the app.
-clear-cache=false
  Clear the cache and re-extract the variant properties such as the application
  ID and the main activity name. Only takes effect when no arguments are
  provided.
-force-install=false
  Force install the target app before starting the activity.
-force-stop=true
  Force stop the target app before starting the activity.
-module=
  Specify which application module to use, when the current directory is the
  top level Gradle project containing multiple sub-modules. When not specified,
  the first available application module is used. Only takes effect when no
  arguments are provided.
-variant=
  Specify which build variant to use. When not specified, the first available
  build variant is used. Only takes effect when no arguments are provided.

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb stop - Stop your app on all devices

Stops your app on all devices.

To stop your app for a specific user on a particular device, use 'madb user set' command to set the default user ID for that device. (See 'madb help user' for more details.)

Usage:

madb stop [flags] [<application_id>]

<application_id> is usually the package name where the activities are defined. (See: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename)

If the application ID is not specified, madb automatically determines which app to stop, based on the build scripts found in the current working directory.

1) If the working directory contains a Flutter project (i.e., has "flutter.yaml"), this command will run "flutter stop --device-id <device serial>" for all the specified devices.

2) If the working directory contains a Gradle Android project (i.e., has "build.gradle"), run a small Gradle script to extract the application ID. In this case, the extracted ID is cached, so that "madb stop" can be repeated without even running the Gradle script again. The ID can be re-extracted by clearing the cache by providing "-clear-cache" flag.

The madb stop flags are:

-clear-cache=false
  Clear the cache and re-extract the variant properties such as the application
  ID and the main activity name. Only takes effect when no arguments are
  provided.
-module=
  Specify which application module to use, when the current directory is the
  top level Gradle project containing multiple sub-modules. When not specified,
  the first available application module is used. Only takes effect when no
  arguments are provided.
-variant=
  Specify which build variant to use. When not specified, the first available
  build variant is used. Only takes effect when no arguments are provided.

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb uninstall - Uninstall your app from all devices

Uninstall your app from all devices.

To uninstall your app for a specific user on a particular device, use 'madb user set' command to set the default user ID for that device. (See 'madb help user' for more details.)

Usage:

madb uninstall [flags] [<application_id>]

<application_id> is usually the package name where the activities are defined. (See: http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename)

If the application_id is not specified, madb automatically determines which app to uninstall, based on the build scripts found in the current working directory.

If the working directory contains a Gradle Android project (i.e., has "build.gradle"), run a small Gradle script to extract the application ID. In this case, the extracted ID is cached, so that "madb uninstall" can be repeated without even running the Gradle script again. The ID can be re-extracted by clearing the cache by providing "-clear-cache" flag.

The madb uninstall flags are:

-clear-cache=false
  Clear the cache and re-extract the variant properties such as the application
  ID and the main activity name. Only takes effect when no arguments are
  provided.
-keep-data=false
  Keep the application data and cache directories. Equivalent to '-k' flag in
  'adb uninstall' command.
-module=
  Specify which application module to use, when the current directory is the
  top level Gradle project containing multiple sub-modules. When not specified,
  the first available application module is used. Only takes effect when no
  arguments are provided.
-variant=
  Specify which build variant to use. When not specified, the first available
  build variant is used. Only takes effect when no arguments are provided.

-d=false
  Restrict the command to only run on real devices.
-e=false
  Restrict the command to only run on emulators.
-n=
  Comma-separated device serials, qualifiers, device indices (e.g., '@1',
  '@2'), nicknames (set by 'madb name'), or group names (set by 'madb group').
  A device index is specified by an '@' sign followed by the index of the
  device in the output of 'adb devices' command, starting from 1. Command will
  be run only on specified devices.
-prefix=name
  Specify which output prefix to use. You can choose from the following
  options:
      name   - Display the nickname of the device. The serial number is used instead if the
               nickname is not set for the given device.
      serial - Display the serial number of the device.
      none   - Do not display the output prefix.
-seq=false
  Run the command sequentially, instead of running it in parallel.

Madb user - Manage default user settings for each device

Manages default user settings for each device.

An Android device can have multiple user accounts, and each user account has a numeric ID associated with it. Certain adb commands accept '--user <user_id>' as a parameter to allow specifying which of the Android user account should be used when running the command. The default behavior when the user ID is not provided varies by the adb command being run.

Some madb commands internally run these adb commands which accept the '--user' flag. You can let madb use different user IDs for different devices by storing the default user ID for each device using 'madb user set' command. If the default user ID is not set for a particular device, madb will not provide the '--user' flag to the underlying adb command, and the current user will be used for that device as a result.

Below is the list of madb commands which are affected by the default user ID settings:

madb clear-data
madb install
madb start
madb stop
madb uninstall

For more details on how to obtain the user ID from an Android device, see 'madb user help set'.

Usage:

madb user [flags] <command>

The madb user commands are:

set         Set a default user ID to be used for the given device.
unset       Unset the default user ID set by the 'madb user set' command.
list        List all the existing default user IDs.
clear-all   Clear all the existing default user settings.

Madb user set

Sets a default user ID to be used for the specified device, when there are multiple user accounts on a single device.

The user IDs can be obtained using the 'adb [<device_serial>] shell pm list users' command. Alternatively, you can use 'madb exec' if you want to specify the device with a nickname. For example, running the following command:

madb -n=MyPhone exec shell pm list users

will list the available users and their IDs on the MyPhone device. Consider the following example output:

[MyPhone]       Users:
[MyPhone]               UserInfo{0:John Doe:13} running
[MyPhone]               UserInfo{10:Work profile:30} running

There are two available users, "John Doe" and "Work profile". Each user is assigned a "user ID", which appears on the left of the user name. In this case, the user ID of "John Doe" is "0", and the user ID of the "Work profile" is "10".

To use the "Work profile" as the default user when running madb commands on this device, run the following command:

madb user set MyPhone 10

and then madb will use "Work profile" as the default user for device "MyPhone" in any of the subsequence madb commands.

Usage:

madb user set [flags] <device_serial> <user_id>

<device_serial> is the unique serial number for the device, which can be obtained from 'adb devices'. <user_id> is one of the user IDs obtained from 'adb shell pm list users' command.

Madb user unset

Unsets the default user ID assigned by the 'madb user set' command for the specified device.

Running this command without any device specifiers will unset the default users only for the currently available devices and emulators, while keeping the default user IDs for the other devices.

Usage:

madb user unset [flags] <device_serial>

<device_serial> is the unique serial number for the device, which can be obtained from 'adb devices'.

Madb user list

Lists all the currently stored default user IDs for devices.

Usage:

madb user list [flags]

Madb user clear-all

Clears all the currently stored default user IDs for devices.

This command clears the default user IDs regardless of whether the device is currently connected or not.

Usage:

madb user clear-all [flags]

Madb version - Print the madb version number

Prints the madb version number to the console.

If this version of madb binary is an official release, this command will show the version number. Otherwise, the version will be in the form of "<version>-develop", where the version indicates the most recent stable release version prior to this version of madb binary.

Usage:

madb version [flags]

Madb help - Display help for commands or topics

Help with no args displays the usage of the parent command.

Help with args displays the usage of the specified sub-command or help topic.

"help ..." recursively displays help for all commands and topics.

Usage:

madb help [flags] [command/topic ...]

[command/topic ...] optionally identifies a specific sub-command or help topic.

The madb help flags are:

-style=compact
  The formatting style for help output:
     compact   - Good for compact cmdline output.
     full      - Good for cmdline output, shows all global flags.
     godoc     - Good for godoc processing.
     shortonly - Only output short description.
  Override the default by setting the CMDLINE_STYLE environment variable.
-width=<terminal width>
  Format output to this target width in runes, or unlimited if width < 0.
  Defaults to the terminal width if available.  Override the default by setting
  the CMDLINE_WIDTH environment variable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL