Running Processing Sketches on Android

edited March 1 in Android Mode

I have added "processing-android-core.jar" file to my Android Studio project. In order to run my Processing sketches on Android Studio I also need classes like "PFragment" and for my project "JSONObject". They are not included in the added "jar-file". It is quite hard to locate those files.

Can anyone point me to the right files?

Kind regards,



  • Answer ✓

    Try exporting your application (or an/any application) from the Processing PDE. Then go to the generated folder and check what jars are being bundle together as part of the export.


  • edited March 1

    Great, this indeed works for most of the code..

    I follow the procedure explained on the website:

    My code to load the code "Sketch.class" is the following:

    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, ViewGroup.LayoutParams.MATCH_PARENT));
        //PFragment is not included in the core library
        sketch = new Sketch();
        PFragment fragment = new PFragment(sketch);
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (sketch != null){
    protected void onNewIntent(Intent intent) {
        if (sketch != null){


    Two errors here: - The "onRequestPermissionsResult" call requires API level 23, this would allow me to target only 40% of devices. Is there a way to circumvent this call and include more devices?

    • The "onNewIntent" call gives an error message "has protected access in Activity"

    Any ideas, suggestions?

    Thank you very much for your help..

  • edited March 1 Answer ✓


    • as for testing p5 code with AS you have only to export it (with P5) as android project; then go to AS and on launch select "import from existing code" and choose your android folder created when you exported as the src code.

    • the call for permissions does not requires API level 23 (or more); the main activity extends appCompatActivity and (with P5) the minSDK is 15 (or 16, i dont remember)

    • put the code you are using in the fragment. Are you using "dangerous permissions"??? - and what version of the android mode are you using?

    • have a look (with AS) to your buil.gradle and your dependencies

  • I have exported it with Processing, then imported it as an Android Project. Seems to work, they use a few additional libraries, now the code seems to work. Only question is how to do this properly with an existing Android Project.

    Will try to add all the libraries and the code and then launch again.. Step in the good direction, thank you!

Sign In or Register to comment.