Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Last active July 19, 2023 10:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phlummox/24b488fa8656cf925014639bab9977e5 to your computer and use it in GitHub Desktop.
Save phlummox/24b488fa8656cf925014639bab9977e5 to your computer and use it in GitHub Desktop.
Android development - command-line cheatsheet

Android development - command-line cheatsheet

See also

Cheatsheet for adb commands, forked from Pulimet/AdbCommands

Download Android command-line tools
mkdir -p $ANDROID_SDK_ROOT/cmdline-tools
unzip -q commandlinetools-linux-*.zip -d /tmp
rm commandlinetools-linux-*.zip
mv /tmp/cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest

Download Android studio

curl -s $ANDROID_STUDIO_URL | sudo tar xf - --gzip -C /opt

Or can use IntelliJ IDEA Community Edition for almost all purposes (& it might be a skerrick faster):

ensure PATH is correct

(if studio is in /opt/android-studio, and SDKs etc under ~/Android/Sdk):


run Android studio

(if it's not on PATH)

Use sdkmanager, avdmanager

The command-line options do NOT follow typical conventions. e.g. "-h" doesn't get you help, it has to be --help; it's "--list_installed", not "--list-installed"

install platform tools, build tools, android platform:

yes  | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager "platform-tools" "build-tools;31.0.0" "platforms;android-31"

install system images:

yes     | sdkmanager "system-images;android-31;google_apis;x86_64"

create device

echo no | avdmanager create avd -n avd28 -k "system-images;android-31;google_apis;x86_64"

list installed packages

sdkmanager --list_installed

sdkmanager help

sdkmanager --help


From project directory,

  • on Mac or Linux: ./gradlew build
  • on Windows: gradlew.bat build

(gradlew is a wrapper which downloads .jar files etc needed to run Gradle - is intended to be more flexible than forcing devs to download particular .jars etc themselves.)

.apk file ends up in app/build/outputs/apk/.

Other gradle tasks

list available tasks:

./gradlew tasks

Install apk file to (currently active) device:

adb install /path/to/some/file.apk

Worth checking out for the other import adb commands/tasks.

Run an app on a physical Android device (over usb or wifi)

Use adb qualified names of all apps/packages. If you forget what your qualified app name, but it's installed on the device, then:

adb shell pm list packages

And then

adb shell monkey -p -v 1

(to be more precise, this runs the app and sends 1 random input to it)

Debugging using a physical Android device (over usb or wifi)

Over USB:

Over wifi:

Connect via ssh tunnel

If the Android device is connected to a remote computer you can ssh to, where you know an adb server is running, use:

ADBPORT=5037; ssh -L${ADBPORT}:localhost:${ADBPORT} me@remotecomputer

adb invocations on the local computer will get forwarded to remotecomputer; port 5037 is the port adb server listens on.

When you don't have direct ssh access

May be able to use adb-proxy, written in python (>= 3.7; see Allows for e.g. ssh "hops", and reverse connections. Simple use, mimicking ssh tunnel above:

  • install adb-proxy: pip install git+
  • on remote computer:
    • connect device to remote computer if needed
    • use adb devices to list devices, record device-id
  • adbproxy connect -s some-device-id -J me@othercomputer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment