Processing for Android

Developing with Android Studio

Use Android Studio for advanced Android development with Processing's core library.

General steps

You should only use Android Studio for Android development if you've already spent time learning how to develop Android applications using Android Studio (separately from Processing), and want to make use of the Processing core library. Android development in Android Studio is significantly more difficult than desktop Processing/Java development with Eclipse. Take time to learn it if you're going this route: get a book, read some Android development tutorials, check Google's developer materials, etc.

In case you already know how to develop Android apps using this advanced IDE, it is not that difficult either. All our core code is bundled inside the, which is inside the AndroidMode folder. You just need to copy this file as processing-core.jar and add it as a dependency to your project. Step by step procedure for Android Studio is as follows:

1. Create an Android project if you haven't already created one:

New project

2. Select the target device:

Select target

3. Add an empty activity:

Add activity

4. Set the name for the main activity class and the layout file:

Customize activity

5. Copy (located in the AndroidMode folder in Processing) to /app/libs, rename it to processing-core.jar, and add it as a jar dependency to the project:

Module settings

6. Then, write your sketch code by extending PApplet, for example:

package tutorials.androidstudio.fragmentsv4;

import processing.core.PApplet;

public class Sketch extends PApplet {
  public void settings() {
    size(600, 600);

  public void setup() { }

  public void draw() {
    if (mousePressed) {
      ellipse(mouseX, mouseY, 50, 50);

7. Initialize the sketch in the main activity:

package tutorials.androidstudio.fragmentsv4;

import android.os.Bundle;
import android.content.Intent;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import processing.core.PApplet;

public class MainActivity extends AppCompatActivity {
  private PApplet sketch;

  protected void onCreate(Bundle savedInstanceState) {
    FrameLayout frame = new FrameLayout(this);
    setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,

    sketch = new Sketch();
    PFragment fragment = new PFragment(sketch);
    fragment.setView(frame, this);

  public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    if (sketch != null) {
      requestCode, permissions, grantResults);

  public void onNewIntent(Intent intent) {
    if (sketch != null) {
The onRequestPermissionsResult() method in the main activity is needed in the case the app uses any dangerous permissions. If missing, the results of requesting the permission to the user will not reach the sketch, and it may fail to work properly. onNewIntent() is also needed so the sketch can handle intents sent to the main activity.

8. Finally, create a simple layout for the main activity:

<RelativeLayout xmlns:android=""
    tools:context="tutorials.androidstudio.fragmentsv4.MainActivity" >

    <FrameLayout android:id="@+id/container"
        android:layout_height="match_parent" />


The complete Android Studio project is available here.

Using Bintray packages

The processing-core library is also available as a package on Bintray. This package can be easily imported into a Gradle project using the following dependency snippet:

compile 'org.p5android:processing-core:x.y.z'

where x.y.z is the desired version to use. In Android Studio, the processing-core package will appear as a module dependency as follows:

Bintray package