Android Command Line Tools

This section provides a list of commonly used Android command line tools that can be executed on the Bourne shell.

The Android system also provided its own programs that you can run on the Bourne shell command line. Here are some examples:

adb (Android Debug Bridge) - "adb" is a command line tool that normally provided on an external system to perform remote access to Android systems. But it is also provided on Android systems that you ran it locally. Here is an example session of running "adb shell" on my Android emulator:

herong> adb shell
   (Running "adb shell" on my Windows system)

# adb shell
   (Running "adb shell" on my Android emulator)

adb shell
* daemon not running. starting it now on port 5038 *
* daemon started successfully *
# exit
exit
#

am (Activity Manager) - "am" is a command line tool that allows you to manage activities like: starting an application activity, stop activities, monitor activities, etc. Here is an example session of running "am start" to start my "AndroidWeb" application:

herong> adb shell am start com.herongyang.web/.AndroidWeb
am start com.herongyang.web/.AndroidWeb
Starting: Intent { act=android.intent.action.MAIN cat=
   [android.intent.category.LAUNCHER]
   cmp=com.herongyang.web/.AndroidWeb }

dumpsys - "dumpsys" is a command line tool that dumps information about system services. Here is an example session:

herong> adb shell dumpsys procstats
CURRENT STATS:
* system / 1000 / v31:
  TOTAL: 100% (251MB-252MB-253MB/139MB-147MB-156MB/537MB-532MB-...)
  Persistent: 100% (251MB-252MB-253MB/139MB-147MB-156MB/537MB-...)
* com.motorola.actions / u0a204 / v301071708:
  TOTAL: 99% (16MB-17MB-18MB/13MB-13MB-14MB/115MB-116MB-117MB over 2)
* com.android.bluetooth / 1002 / v31:
  TOTAL: 99% (25MB-26MB-27MB/15MB-16MB-17MB/92MB-96MB-99MB over 2)
  Persistent: 99% (25MB-26MB-27MB/15MB-16MB-17MB/92MB-96MB-...)
* com.android.systemui / u0a297 / v31:
...

dalvikvm (Dalvik VM) - "dalvikvm" is a command line tool that allows you to launch the Dalvik VM to run a Java class in DEX format. Here is an example session of running "dalvikvm -version":

herong> adb shell dalvikvm -showversion
dalvikvm -showversion
ART version 2.1.0

logcat - "logcat" is a command line tool that allows you to dump log entries from 3 log buffers: main, events and radio. Here is an example session of running "logcat" on my Android emulator:

herong> adb shell

# logcat *:E
logcat *:E
--------- beginning of system
--------- beginning of crash
E/AndroidRuntime( 1819): FATAL EXCEPTION: main
E/AndroidRuntime( 1819): Process: com.herongyang.debug, PID: 1819
E/AndroidRuntime( 1819): java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.herongyang.debug/com.herongyang.debug.
AndroidDebug}: java.lang.IllegalStateException: The specified child
already has a parent. You must call removeView() on the child's parent
first.
,,,
^C

monkey - "monkey" is a command line tool that allows you to perform a monkey testing on an application. Here is an example session of running "monkey" to perform a monkey test on my "AndroidWeb" application:

herong> adb shell

# monkey -p com.herongyang.web 500
monkey -p com.herongyang.web 500
    // Injection Failed
    // activityResuming(com.android.documentsui)
    // Injection Failed
    // activityResuming(com.android.documentsui)
    // Injection Failed
Events injected: 500
## Network stats: elapsed time=31980ms (0ms mobile, 0ms wifi, 31980ms
not connected)

pm (package manager) - "pm" is a command line tool that allows you to manage application packages. Here is an example session of running "pm" to list features and packages:

herong> adb shell

# pm list features
pm list features
feature:reqGlEsVersion=0x0
feature:android.hardware.audio.output
feature:android.hardware.bluetooth
feature:android.hardware.camera
feature:android.hardware.camera.any
feature:android.hardware.camera.autofocus
...

# pm list packages
pm list packages
package:com.android.smoketest
package:com.example.android.livecubes
package:com.android.providers.telephony
package:com.herongyang.web
package:com.android.providers.calendar
package:com.android.providers.media
package:com.android.protips
package:com.android.launcher
package:com.android.documentsui
package:com.android.gallery
package:com.android.externalstorage
package:com.android.htmlviewer
package:com.android.quicksearchbox
package:com.android.mms.service
package:com.android.providers.downloads
package:net.sf.andpdf.pdfviewer
package:com.android.browser
...

screenrecord - "screenrecord" is a command line tool that allows you to record the display of device in a MPEG-4 file. Here is an example session:

herong> adb shell

# screenrecord /sdcard/Movies/demo.mp4

(go to the device and play with some apps)
(press Control + C to stop)

# ls -l /sdcard/Movies/
-rw-rw---- 1 root everybody 166173285 2023-06-01 22:15 demo.mp4

More tutorial examples on using these command line tools are provided in other sections.

Table of Contents

 About This Book

 Installing JDK 1.8 on Windows System

 Installation of Android SDK R24 and Emulator

 Installing Apache Ant 1.9 on Windows System

 Developing First Android Application - HelloAndroid

 Android Application Package (APK) Files

 Android Debug Bridge (adb) Tool

 Android File Systems

 AboutAndroid - Application to Retrieve System Information

 android.app.Activity Class and Activity Lifecycle

 View Objects and Layout Resource Files

 Using "adb logcat" Command for Debugging

 Build Process and Package File Content

 Building Your Own Web Browser

Android Command Line Shell

 What Is the Bourne Shell?

 Bourne Shell Command Line Examples

 Unix/Linux Command Line Programs

Android Command Line Tools

 "dalvikvm" Command to Run Java Application

 Samsung Galaxy Tab 3 Mini Tablet

 USB Debugging Applications on Samsung Tablet

 Android Tablet - LG-V905R

 USB Debugging Applications on LG-V905R Tablet

 Android Phone - LG-P925g

 USB Debugging Applications on LG-P925g Phone

 Archived Tutorials

 References

 Full Version in PDF/EPUB