Building Processing for Android

codeanticode edited this page Jul 4, 2018 · 31 revisions

The build system of Processing or Android is entirely based on Gradle (Ant support was removed because there are many critical steps, particularly related to dependency resolution, that cannot be easily implemented with Ant), and it includes Android Studio sample projects for developing and testing the core, VR, and any other Android-specific libraries. Eclipse projects for the Android mode and the SDK Updater tool are also provided.

Building everything with Gradle

The build system uses gradle to build processing core and mode, the vr library, and the SDK Downloader tool, and to create the Android mode package ready to use.

First of all, download and install the Android SDK. All you need are the command line tools (available at the bottom of this page). Using the command line tools, you can download all the required components of the Android SDK. In order to build the Android mode, you only need to install the Android SDK Tools, the SDK Platform-tools, the Build-tools, and the SDK Platform for Android 8 (API 26).

Then, create a file in the root folder of the repo with the following contents:

sdk.dir=<path to Android SDK>

If you are on Windows, use either double back slashes "\" as the file separator, or forward slashes "/" (Unix-style). Otherwise, the build process will fail. Alternatively, the build script will try to create this file automatically if the ANDROID_SDK environmental variable is defined in the system.

Once a valid is available, you can build the Android mode distribution by running:

gradle dist 

This assumes you have Gradle (version 4.1 or higher) available globally in your system, alternatively you can use the gradle wrapper which is included:

./gradlew dist

and will download all the required gradle files for proceed with the build process.

If the build process of all modules concludes succesfully, the and the AndroidMode.txt files will be stored in the dist subfolder.

The jar, md5, and pom files needed to upload processing-core and processing-vr to JCenter are also generated inside core/dist and mode/libraries/vr/dist

Clean all build files with:

gradle clean


./gradlew clean

if using gradle wrapper.

Note that the ant build scripts are no longer provided to build the mode or core library.

Developing/debugging/testing the Core and VR libraries with Android Studio

Import the folder studio into Android Studio, okay the Gradle Sync dialog that shows next, and wait for Android Studio to download all the dependencies. You should get a project space where you can run the provided sample apps (simple and vrcube), add new apps, and modify and debug the core and vr libraries. The processing-core and processing-vr Android library projects simply point to the source folders in core/src and mode/libraries/vr/src, so any changes in the source code files in those locations will affect the sample apps.

Running the Android mode from Eclipse

The Android mode is a Java project that can be developed from a Java IDE such as Eclipse or IntelliJ. The Eclipse project files are included, and the steps required to get the mode to run from Eclipse are as follows:

I - Setting up Processing

Since we only require processing as a dependency, perform a shallow clone of the processing repo and build it by running ant in the processing/build folder, as detailed in the build instructions for Processing:

git clone --depth 1

II - Import Processing repos into Eclipse

  1. Import the Processing repo into Eclipse: Import > Projects from Git > Existing local repository > Select Processing folder > Import existing eclipse project
  2. Select:
    • processing-app
    • processing-core
    • processing-java (Select the option with path processing/java)
  3. Right click the processing-app project and select Run As > Java Application > “Base -”

III - Import android-mode project into Eclipse

  1. Build the processing for Android distribution using gradle, and then Import the Processing for Android repo into Eclipse: Import > Projects from Git > Existing local repository > Select Processing folder > Import existing eclipse project
  2. Select:
    • android-mode
    • android-mode-sdkupdater
  3. Right click the android-mode package > Build Path > Configure Build Path
  4. Add the classpath variables ANDROID_SDK and ANDROID_JAR, and set the first to the path of your Android SDK, and the second to the android.jar file located in the platforms/android-xx folder of the SDK (where xx is the Android API level).
  5. Add/Edit the Run Configuration to the processing-app needed to load the Android mode from the development repository:
    1. Right click on the processing-app project, and select Run As...|Run Configurations
    2. Create a new run configuration or edit the existing configuration, making sure it has processing-app as the project, and as the main class.
    3. In the arguments tab, enter${resource_loc:/android-mode} as VM arguments.
  6. Every time there is a change in the mode source (or in the core or VR libraries) you need to repackage the mode before running from Eclipse. To do so, run the “gradle dist” command in the processing-android root folder, as discussed in the before.
  7. Start processing-app from the run menu. The Android Mode should now be present in the Mode menu.
  8. In order to run a debug session including breakpoints in the source code, add the processing and processing-android folders in the Source tab of Run Configurations dialog.
  9. You could create a new builder that runs gradle dist every time the android-mode project is built by Eclipse. This is done by going to the project's properties, then to the Builders option and select New. There, you should set the working directory as the location of local processing-android repo, browse for the gradlew command to use in Location, and add dist as argument. This builder should be moved up before the default Java Builder.

Running the Android mode from IntelliJ

The Android mode source can be imported into a new IntelliJ project quite easily. As with Eclipse, we need to clone the Processing repo first. Then:

II - Import Processing repos into IntelliJ

  1. Import the repo into IntelliJ: Import Project > Select Processing folder > Import from external model (Eclipse)
  2. In the “Select Eclipse projects to import” window, select
    • processing-app
    • processing-core
    • processing-java (java)
  3. Goto Run > Edit Configurations and create a new Application configuration.
    1. Set “Main class” to “Base (”
    2. And “Use classpath of module” to “processing-app”

III - Import android-mode project into IntelliJ

  1. Go to File > Project Structure > Modules > Add > Import Module > Select Processing-Android folder > Import module from external model (Eclipse) > Select all projects
  2. Go to File > Settings > Appearance & Behaviour > Path Variables and set the ANDROID_SDK and ANDROID_JAR variable’s (create if not present) values to your Android SDK path and the android.jar file located in the platforms/android-xx folder of the SDK (where xx is the Android API level), respectively. Also create a new variable called PROC_AND (or anything you want) and set its value to <path to processing-android repo>/mode.
  3. Run the "gradle dist" command in the processing-android folder to build the core library and the mode.
  4. Set the VM options parameter of the run configuration to$VAR$. Replace VAR with the variable you created in step 2 (e.g.: PROC_AND).
  5. Run the project. The Android Mode should now be present in the Mode menu.
  6. The "gradle dist" step can be made it automatically by check the 'Before launch' section for your run config.

Special tasks

These are some special tasks that only need to be run occasionally to update the Gradle wrapper included in the repo, or the Android permissions supported by the mode.

Update Gradle wrapper for entire project:

Run the following command to update the bundled Gradle wrapper:

gradle wrapper --gradle-version 4.4.1

(replacing 4.4.1 by the version you want to update to). Then, you have to commit the new Gradle wrapper files to the repo.

Mode-specific tasks:

  1. Update with the latest documented permissions:
cd mode
gradle permissions
  1. Downloads and zips the gradle wrapper files required by the mode when it runs in the PDE:
cd mode
gradle wrapper

Add --rerun-tasks to the command if the Gradle says that the task is up-to-date and refuses to update.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.