Using Android Debug Bridge with Collect

Android Debug Bridge is a tool that provides command-line access to a USB-connected Android device. It can be used to move files between the device and your computer, install applications, and take screenshots and videos. When connected to a device that has ODK Collect installed, it can be used to push blank form definitions and pull completed forms.

Installing and setting up ADB

Android Studio

The easiest and most well-supported way to install ADB is to install Android Studio, which includes ADB. After installing, you'll need to enable USB Debugging.

Warning

Remember to disable USB Debugging after you're done.

Standalone ADB

You can also install ADB without Android studio. This is not well supported, though, and should only be done if you cannot install Android Studio on your computer.

Managing forms with ADB

Form definitions are stored on the device in the forms subdirectory of your Collect directory.

Loading blank forms

$ adb push local/path/to/form.xml <collect-directory>/forms/form.xml

Note

The target path on the phone (the last part of the command) must include the file name.

Deleting forms

$ adb shell rm -d <collect-directory>/forms/form.xml

Downloading forms to your computer

To download all filled records from a device:

$ adb pull <collect-directory>/instances/*

Developer tasks and troubleshooting with ADB

Downloading Collect databases

Collect stores form definition and form record state information in a few SQLite databases, which you can pull onto your local computer.

$  adb pull <collect-directory>/metadata/*.db

Taking screenshots

$ adb exec-out screencap /sdcard/image-name.png

To pull the saved image locally:

$ adb pull /sdcard/image-name.png

Note

ODK Docs contributors can use the screenshot utility script, which wraps the adb commands and assists with saving the images to the correct location and inserting appropriate markup in the documentation source.

Recording video

$ adb shell screenrecord /sdcard/video-name.mp4

When you hit Enter, the video starts recording immediately.

To stop the recording, press CTRL-C. If you don't interrupt the recording, it will stop after three minutes.

To pull the video locally:

$ adb pull /sdcard/video-name.png

Capturing logs for debugging

Capturing in-progress logs with logcat

If you are experiencing crashes or other serious glitches, and you can reproduce the bug, use adb logcat to capture log events during the crash.

  1. Before reproducing the bug, begin piping logs to a file:

    $ adb logcat > logfile.txt
    

    This will write all logged errors to your local file logfile.txt as they occur.

  2. Reproduce the bug or crash event.

  3. Type CTRL-C to stop logging.

You can then upload the logfile.txt file to a a support forum post.

Pull a bug report

If more in-depth information is needed, you can pull a complete bug report from the device.

$ adb bugreport

This copies a ZIP file locally containing all system messages, error logs, and diagnostic output, along with information about the device's hardware, firmware, and operating system.

Identifying the Collect directory on your device

The ODK Collect directory location on your device depends on which version of Collect you have:

  • <= v1.26.0: /sdcard/odk. Was available to other applications to integrate, but as of August 2020, Google no longer allows globally accessible storage.

  • >= v1.26.0: /sdcard/Android/data/org.odk.collect.android/files. Only accessible by Collect.

  • >= 2021.2: /sdcard/Android/data/org.odk.collect.android/files/projects. Only accessible by Collect. The Project directories will contain a blank file with the same name as the Project itself.

Did this page help you?

Selecting an option will open a 1-question survey

👍 Yes 👎 No