Skip to content

Android Mode Structure

Deeraj Esvar R edited this page Mar 21, 2019 · 3 revisions

The Android mode is based upon the Java mode, and adds the functionality to build Processing sketches with Android-specific features and run them on devices, either physical or virtual through the emulator. The Android mode includes the core library that is needed for the sketches to access the Processing API on Android. It also requires the Android SDK for resolving dependencies from the Android platform and for using its tools to communicate with the devices and to create app packages.

Code Editor

The code editor is very similar to that in the Java mode, but with some Android-specific additions: Export signed package and Android project under the File menu, Run on device and in emulator under Sketch, and the Android menu with sketch permissions, app-type selector, device selector, and tools (including the SDK Updater). The source code of the editor is in the AndroidEditor.java file, which contains the menu initialization and handling. The toolbar with the run/stop buttons and the mode selector is also derived from the Java toolbar, and its implementation in AndroidToolbar.java incorporates the changes required by the Android mode.

The Android SDK

The Android mode needs access a local copy of the Android SDK in the computer, in order to satisfy the Processing sketches' dependencies on the Android platform and also to use the tools that the SDK provides to communicate with the devices, download and update the SDK file, and perform other basic functions. The AndroidSDK.java class handles all of this, starting with searching a valid SDK in the local disk. If no such SDK is found, the mode will ask the user to either locate one manually, or download the SDK automatically. The SDK download is implemented in the SDKDownloader class, which queries Google's repositories to extract the URLs of the remote locations of the platform, tools, build tools, platform tools, and emulator packages. The SDK gets downloaded into <sketchbook folder>/android/sdk but this location can be modified Processing's properties file.

Interfacing with the Android Debug Bridge

The Android Debug Bridge or adb is a command-line tool from the Android SDK that allows communication with devices. The Android mode uses adb to perform basic tasks as querying the connected devices and installing a built package on a selected device. A call to the adb tool in the mode is possible with the runADB(final String... cmd) method in the AndroidSDK class, where the argument is the list of command-line arguments required by adb.