Problem with running a simple sketch on Android

Hello,

For my vinyl jukebox project, which runs with processing, I would like to make an app to control the jukebox through wifi.

This is the first time I try to make an program for Android.
I installed successfully Processing4 and the android mode on my PC with windows11. The sdk was also installed with the automatic method successfully, and so was the emulator.
My phone (Xiaomi MI11) is in USB debug mode and I can see it is connected via the Android/devices menu.

When I launch the example sketch from the android for processing tutorial , I have an encouraging last message in the console:

BUILD SUCCESSFUL in 19s
27 actionable tasks: 27 executed

But I also have these lines just before:

Task :app:compileDebugJavaWithJavac
Annotation processing got disabled, since it requires a 1.6 compliant JVM
Task :app:dexBuilderDebug
Task :app:desugarDebugFileDependencies
Task :app:mergeExtDexDebug
Task :app:mergeDexDebug
Task :app:packageDebug
Task :app:createDebugApkListingFileRedirect
Task :app:assembleDebug
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use ‘–warning-mode all’ to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See Command-Line Interface

My phone then prompts if I want to install the app. After pressing the “Install” button on the phone, the program seems to be launched because the screen becomes white for a tenth of a second before showing the home menu again. I also get a lot of error messages lines, starting with:

FATAL EXCEPTION: main
Process: processing.test.tutoandroid, PID: 24658
java.lang.VerifyError: Rejecting class processing.a2d.PSurfaceAndroid2D that attempts to sub-type erroneous class processing.core.PSurfaceNone (declaration of ‘processing.a2d.PSurfaceAndroid2D’ appears in /data/app/~~-bvU_owdL5jMbZ3fu757Kw==/processing.test.tutoandroid-rBHYAJjU_SUzumhNmU4O-Q==/base.apk)
at processing.a2d.PGraphicsAndroid2D.createSurface(PGraphicsAndroid2D.java:180)
at processing.core.PApplet.initSurface(PApplet.java:538)

and ending with:

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
Caused by: java.lang.VerifyError: Verifier rejected class processing.core.PSurfaceNone: android.content.Context processing.core.PSurfaceNone.getContext() failed to verify: android.content.Context processing.core.PSurfaceNone.getContext(): [0x22] can’t resolve returned type ‘Reference: android.content.Context’ or ‘Unresolved Reference: android.support.wearable.watchface.WatchFaceService’ (declaration of ‘processing.core.PSurfaceNone’ appears in /data/app/~~-bvU_owdL5jMbZ3fu757Kw==/processing.test.tutoandroid-rBHYAJjU_SUzumhNmU4O-Q==/base.apk)
… 31 more

If I run the program with the emulator, the behaviour is exactly the same: the emulator is launched, the white screen for a fraction on second, and the same error messages on the console.

Here is the code from the tutorial that I am trying to run:

void setup() {
  fullScreen();
  noStroke();
  fill(0);
}

void draw() {
  background(204);
  if (mousePressed) {
    if (mouseX < width/2) {
      rect(0, 0, width/2, height); // Left
    } else {
      rect(width/2, 0, width/2, height); // Right
    }
  }
}

At this point, I am stuck!
Does anybody know what the problem is and point me on how to solve it?

Hi

With processing 3.5.4 run fine

Runs ok here on my Windows 11 system Processing version 4.1.1 with a Nexus 4 device. Sounds like you’re doing ok up until you go to install it on your device. The error message mentions ‘Unresolved Reference: android.support.wearable.watchface.WatchFaceService’. Are you trying to install it on a smartphone or tablet?

1 Like

I try to run the code on a smartphone .
My version of processing is 4.1.2. I will try tomorrow with the 4.1.1 version.

The 3.5.4 version is the one I normally use, but I was unable to correctly install the SDK with it: despite I accepted the licenses when I was prompted to after the automatic SDK installation, the build fails with error messages in the console, saying that some licences were not approved.
I tried to approve these licences, with the “sdkmanager --licences” command from the tool/bin folder of the SDK, but with no success (error message saying that class files are not compatible with the Java Runtime Environment). That is why I then switched to Processing 4…

Should run with either version.

I tried today with the 4.1.1 version: the problem remains, with the exact same behaviour.

I also tried on an other PC with windows 10, with fresh installations of processing 3.5.4, and later of processing 4.1.2, and got exacly the same behaviour as on the other PC with windows11:

  • With the 4.1.2, the app on the phone that uploads, runs and crashes immediately, with the very same error messages as I described earlier.

  • With the 3.5.4, the same problem (with exactly same error messages) with the non approved licenses.

Tried also with another phone (LG G6), but no way to get it recognized as a device by processing, nor to find a USB driver for it…

Any Idea of what else I can do?

Are we certain that USB debugging is turned on? It should recognize that LG G6. You have to tap the screen a number of times (at least seven as I recall) to activate it.

Does Android Studio recognize either of your Android devices?

Yes, it is in the usb debug mode.
I activated the developer mode by tapping the serial some times, and then activated the usb debug mode.
Maybe the problem with the g6 is rather a matter of usb driver, but I was unable to find the driver for that phone…

I tried the apde processing app, from he playstore. My sketch works with it, but is not very handy to write code directly from a phone…
Moreover, just trying to import the processing.net:
import processing.net.*;

Throws these error messages in the console, so I guess I won’t be able tu use this library that I will need for my project.

Initializing build sequence…
Deleted old build folder
No library found for processing.net
Injected log broadcaster
Detected architecture arm64-v8a

Packaging resources with AAPT…
Compiling with ECJ…

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20230129c/sketch_20230129c.java (at line 8)
    import processing.net.*;
    ^^^^^^^^^^^^^^
    The import processing.net cannot be resolved

  1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/sketch_20230129c/sketch_20230129c.java (at line 23)
    Client myClient;
    ^^^^^^
    Client cannot be resolved to a type

2 problems (2 errors)
Compiling with ECJ failed

Svan, just to know if I should continue with processing or not for my project, can you tell me if the sketch still runs ok with your system with "import processing.net.*; " at the beginning of the sketch?

It fails with “import processing.net” You shouldn’t have to be doing all these gymnastics.

Screen Shot 2023-01-29 at 3.31.35 PM

Have you tried Android Studio to see if it recognizes your devices?

Detected architecture arm64-v8a

Who has the arm64?

Ok, thank you for this information :sweat_smile:

Tried with android studio. The lg g6 is still not recognised but everything is ok with the Xiaomi.
Moreover, I can successfully download apps on the phone with AS.

So I will stop trying with processing for now, looks it is not appropriate for what I want to do.
It’s a pity, I love processing and I never used AS before. Hope it will not be too hard to learn :sweat_smile:

It’s a pity, I love processing and I never used AS before.

There is a way to use Processing code in Android Studio; the reference is here: https://android.processing.org/tutorials/android_studio/index.html. It involves importing fundamental Processing library files into AS.

A lot of libraries don’t seem to work with Processing for Android, even some that are supposed to be compatible, and there doesn’t seem to be a lot of interest on the part of the developers (assuming the library hasn’t already been abandoned) to get them to work. So IMHO, as long as you don’t need to use any add-on libraries, P4A is great. Otherwise, go with Android Studio. I’ve just started to learn AS myself.

There may also be issues depending on which version of Android you’re on. I’m not familiar with the devices you mentioned, but that might be something to look into.

1 Like

First step done!
Thanks to the tutorial you mentionned ,svan, I was able to run a processing sketch on my phone using Android Studio! It even works very well with the emulator!

But the problem with the import processing.net.*; still remains. I guess that as said David, this library won’t work with processing for android…

I have seen that some examples exist in Android Studio, to make client/server applications. I am going to dig through that…
I am really new to android Studio, so I don’t know if it will be possible but maybe a “mix” with processing and these client/server example is possible?

Not sure that it would work, but could also try directly adding the library to Processing’s library folder by drag and dropping it onto the sketch (I have not tried it). Alternatively might be able to add it to AS.

I am not sure to know AS enough to do that but I can try.
where can I fin this library in processing?

In your Documents/Processing folder is a folder called ‘libraries’. The library that you want to use should be in that folder. It might be better if you let Processing place it in there as opposed to copy/pasting it in there yourself, but you can try both ways. Supposedly dragging and dropping the library that you want to add onto your sketch will cause it to automatically be added to the libraries folder. I’ve never done it myself but have heard other forum members describe this technique; it might be worth a try. As far as AS you would probably use a technique similar to what you used to add the Processing libraries.

I’m not sure what the processing.net.* library does or who owns it. Is it associated with Processing.org or is it a proprietary library used for billing? I was unable to find it on the internet.

Hi

1 Like

Thank you. We ought to be able to add this to the project.

Hi

Read this

1 Like