Installed Apps Crashes using Processing 4.2 Android Mode

Installing codes using processing 4.2, even if the given sample codes are successfully installed on the Android device/phone, crashes when I try running them. It worked before in processing 3, can’t find the issue. Any insights that you could share?

Thank you

Hi @Myrdalm,

Welcome to the forum! :wink:

Without any information about your device / logs in the output window we can’t help you further with this!

Can you provide more debug material?

2 Likes

Hi

1 Like

Hello,

I used the NoBackgroundTest code sample

void setup() {
size(400, 400, P2D);
background(255, 0, 0);
fill(255, 150);
}

void draw() {
ellipse(mouseX, mouseY, 100, 100);
}

And below is the output in the console:

Build folder: C:\Users\MMM\AppData\Local\Temp\android15489222564811472272sketch
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.1.0) was tested up to compileSdk = 32

This warning can be suppressed by adding
android.suppressUnsupportedCompileSdk=33
to this project’s gradle.properties

The build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdk = 33
Observed package id ‘platforms;android-33-ext5’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-ext5’)
Observed package id ‘platforms;android-33’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-2’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’)

Task :app:preBuild UP-TO-DATE
Task :app:preDebugBuild UP-TO-DATE
Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
Task :app:compileDebugAidl NO-SOURCE
Task :app:compileDebugRenderscript NO-SOURCE
Task :app:generateDebugBuildConfig
Task :app:javaPreCompileDebug
Task :app:generateDebugResValues
Task :app:generateDebugResources
Task :app:checkDebugAarMetadata
Task :app:createDebugCompatibleScreenManifests
Task :app:extractDeepLinksDebug
Task :app:mergeDebugResources
Task :app:processDebugMainManifest
Task :app:processDebugManifest
Task :app:mergeDebugShaders
Task :app:compileDebugShaders NO-SOURCE
Task :app:generateDebugAssets UP-TO-DATE
Task :app:mergeDebugAssets
Task :app:compressDebugAssets
Task :app:processDebugJavaRes NO-SOURCE
Task :app:checkDebugDuplicateClasses
Task :app:mergeDebugJavaResource
Task :app:mergeDebugJniLibFolders
Task :app:mergeDebugNativeLibs NO-SOURCE
Task :app:stripDebugDebugSymbols NO-SOURCE
Task :app:validateSigningDebug
Task :app:processDebugManifestForPackage
Task :app:writeDebugAppMetadata
Task :app:writeDebugSigningConfigVersions
Task :app:processDebugResources

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

BUILD SUCCESSFUL in 37s
27 actionable tasks: 27 executed

Though it is installed successfully, when I run the app, the app in the phone crashes, this only started when I started using processing which does not happen before when I used processing 3.

Hi @Myrdalm.
What version of Android is installed on your device? Which version of Android mode do you have installed with Processing?

Also use the Processing Android examples to be certain that isn’t the issue. Try:

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
    }
  }
}

Finally, check the Processing console print out for any other information. Usually it will provide information on what was the cause of the crash. If not there are apps for Android that print the crash logs. We need more info to figure out the issue.

I am using the Android 11 Version on my device. I am using Android Mode 4.5.1. intstalled with Processing. SDK updater has also updated everything to all the latest versions.

The sample I used on my first test was from a Processing Android example.
The code you used also had the same issue as the code I used earlier.

Processing console print is the same as before, copied and paste below:

Build folder: C:\Users\MMM\AppData\Local\Temp\android12071222152819130336sketch
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.1.0) was tested up to compileSdk = 32

This warning can be suppressed by adding
android.suppressUnsupportedCompileSdk=33
to this project’s gradle.properties

The build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdk = 33
Observed package id ‘platforms;android-33-ext5’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-ext5’)
Observed package id ‘platforms;android-33’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-2’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’)

Task :app:preBuild UP-TO-DATE
Task :app:preDebugBuild UP-TO-DATE
Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
Task :app:compileDebugAidl NO-SOURCE
Task :app:compileDebugRenderscript NO-SOURCE
Task :app:generateDebugBuildConfig
Task :app:javaPreCompileDebug
Task :app:generateDebugResValues
Task :app:generateDebugResources
Task :app:checkDebugAarMetadata
Task :app:createDebugCompatibleScreenManifests
Task :app:extractDeepLinksDebug
Task :app:mergeDebugResources
Task :app:processDebugMainManifest
Task :app:processDebugManifest
Task :app:mergeDebugShaders
Task :app:compileDebugShaders NO-SOURCE
Task :app:generateDebugAssets UP-TO-DATE
Task :app:mergeDebugAssets
Task :app:compressDebugAssets
Task :app:processDebugJavaRes NO-SOURCE
Task :app:checkDebugDuplicateClasses
Task :app:mergeDebugJavaResource
Task :app:mergeDebugJniLibFolders
Task :app:mergeDebugNativeLibs NO-SOURCE
Task :app:stripDebugDebugSymbols NO-SOURCE
Task :app:validateSigningDebug
Task :app:writeDebugAppMetadata
Task :app:writeDebugSigningConfigVersions
Task :app:processDebugManifestForPackage
Task :app:processDebugResources

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

BUILD SUCCESSFUL in 36s
27 actionable tasks: 27 executed

After using and updating processing android 4 and returning to processing 3, processing 3 is also not working anymore.

Hi this works with processing 3

@Myrdalm,
If you are not seeing any other errors than the only other thing I can think of is to try setting your target sdk to 31 in your AndroidManifest.xml or you could change your compile sdk to 31 but you would have to have that installed.
It looks like you’re compiling for sdk 33, aka Android 13, which usually doesn’t break things when testing on lower versions. But that is the only thing I can see that is different.
Otherwise there are Android apps that let you read the debug log and there may be more information there, but it doesn’t appear that you are doing anything “wrong.” So my guess is it is either the device itself or the sdk version.

1 Like

I tried using processing 3, but now it is updated with processing for, it is not working anymore compared to before. Below is the SS when I use processing 3 now.

How do I set target sdk? I prefer using processing 4 though, due to the reason that it is the latest version.

Have you tried using processing 4 in Android 11, 12 and 13? If so, can you share what you experienced and did it worked?

I would appreciate it if you would be able to help me make it work instead of it crashing.

Thank you

You can set the target sdk by editing the Preferences file. On a Windows 11 system it is located at C:/Users/yourName/AppData/Roaming/Processing/Preferences. However, when I try to change the value from 33 to 32, it just overwrites the file when I run the app the next time and sets it back to 33. The edit doesn’t ‘stick’; and yes, the Processing editor was closed when I made the change. I have an experience similar to yours and I run in Android mode on both Windows and Mac. The last update made it impossible for me to use the Windows OS for Processing Android apps. I got the Mac version to run after downloading a custom Android mode from github:https://github.com/processing/processing-android/issues/729#issuecomment-1516919114
Addendum:
I just replaced the Android mode file on my Windows system with the github file above and it is now fixed; Android runs as expected except for the Gradle warning (which I have yet to figure out how to fix). However, my issue may be different from the one you are experiencing.

Hi @Myrdalm
Yes, I’ve used the Android mode on devices from Android 10-13 using P4 on both Mac and Win10. I’ve used Samsung, Pixel and OnePlus devices. The only time I have had an app crash on startup is when it was accessing an API that wasn’t available. For example a new feature only available in Android 13 but not in my target build of Android 12.
Short from updating to a new device, my only other recommendation is to revert to an older Android mode and Android Sdk install until it works. You would have to do this manually. It seems like the updated Android mode is breaking the build for your device.
You could also try looking at the crash reports. Connect your device to your machine, using the Command Prompt or Terminal (adb needs to be added to your Environment Variables or shell commands):
adb logcat -b crash
and see what happens when you open the crashing app. There are also LogCat reader apps for Android devices.

1 Like

I don’t have mac and I only use Windows 10, can’t afford to buy additional gadgets as of now. May I know where the Android mode folder can be found? Hope your solution can work, I’ve been struggling since I used processing 4.

Thank you

How do I add the adb to my Environment Variables, do I need to install something?

On my Windows system it’s in C:/Documents/Processing/modes. You might want to change the name of the original AndroidMode folder to something like AndroidMode_orig, otherwise any new download will overwrite the old one. Hope it works for you.

Your solution worked so far, it seems that the issue is in the Android mode folder. Though I will still try testing it with more complicated codes and update, here again, codes that involve Bluetooth if P4 affected it.

The solution so far is very helpful.

Thank you

I tried including bluetooth codes that used to work with processing 3, now it does not. If you could give me feedback or a solution, that would be great, but if not, maybe I should give up in using processing android, for everytime processing upgrades, problems always arise.

Here is the code incorporated with bluetooth codes:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.Toast;
import android.view.Gravity;
import android.bluetooth.BluetoothAdapter;
//import android.bluetooth.BluetoothManager; //added
import android.bluetooth.BluetoothDevice;
import java.util.UUID;
import android.os.Looper;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.app.Activity;

public BluetoothSocket scSocket;

boolean foundDevice=false;
boolean BTisConnected=false;
String serverName = "ArduinoBasicServer";

// *** For GUI Communicaion *** //
public static final int MESSAGE_WRITE = 1;
public static final int MESSAGE_READ = 2;
private static final int RESULT_OK = 1;
String readMessage="";
SendReceiveBytes sendReceiveBT = null;

// *** For Bluetooth Initialization *** //
@SuppressWarnings("deprecation")
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
//BluetoothManager bluetoothManager = (BluetoothManager)getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
//BluetoothAdapter bluetooth = bluetoothManager.getAdapter();


// *** For Bluetooth Features *** //
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  if(requestCode==0) {
  if(resultCode==RESULT_OK) {
  background(0);
  ToastMaster ("Bluetooth has been switched ON");
  ToastMaster("Please Reload Application to Connect to Device");
  ToastMaster("Please Reload Application to Connect to Device");
  ToastMaster("Please Reload Application to Connect to Device");
  } else {
  background(0);
  ToastMaster("You need to turn Bluetooth ON !!!");
  ToastMaster("You need to turn Bluetooth ON !!!");
  ToastMaster("You need to turn Bluetooth ON !!!");
  }
  }
}

BroadcastReceiver myDiscoverer = new myOwnBroadcastReceiver();
BroadcastReceiver checkIsConnected = new myOwnBroadcastReceiver();

// *** For GUI Communication *** //
private final Handler mHandler = new Handler(Looper.getMainLooper()) {  
  @ Override
  public void handleMessage(Message msg) 
     {
  switch (msg.what) 
      {
  case MESSAGE_WRITE:
  break;
  case MESSAGE_READ:
  byte[] readBuf = (byte[]) msg.obj;
  readMessage = new String(readBuf, 0, msg.arg1);
  break;
    }
  }
};

// *** For GUI Setup *** //
void setup() {
  fullScreen();
  noStroke();
  fill(0);
 
// *** For Bluetooth Features *** // 
  if (!bluetooth.isEnabled()) {
  Intent requestBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
  this.getActivity().startActivityForResult(requestBluetooth, 0);
  }

  if (bluetooth.isEnabled()) {
  this.getActivity().registerReceiver(myDiscoverer, new IntentFilter(BluetoothDevice.ACTION_FOUND));
  this.getActivity().registerReceiver(checkIsConnected, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));

  if (!bluetooth.isDiscovering()) {
  bluetooth.startDiscovery();
  }
  }
}

// *** GUI Proper Design Setup *** //
void draw() {
  if(foundDevice) {
    if(BTisConnected){
      background(204);
      if(mousePressed){
        if (mouseX < width/2) {
          rect(0, 0, width/2, height); // Left
          byte[] myByte = stringToBytesUTFCustom("L");
          sendReceiveBT.write(myByte);
        } else {
          rect(width/2, 0, width/2, height); // Right
          byte[ ] myByte = stringToBytesUTFCustom("R");
          sendReceiveBT.write(myByte);
        }
      }
    }
  }
}
      
// *** For Bluetooth Features *** //
public class myOwnBroadcastReceiver extends BroadcastReceiver {
  ConnectToBluetooth connectBT;
 
  @Override
  public void onReceive(Context context, Intent intent) {
  String action=intent.getAction();
  
  if(BluetoothDevice.ACTION_FOUND.equals(action)){
  String discoveredDeviceName = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
  //@SuppressWarnings("deprecation") // -- OLD
  //BluetoothDevice discoveredDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); -- Deprecaded Code
  BluetoothDevice discoveredDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE,BluetoothDevice.class);
  foundDevice=true;
  
  if(discoveredDeviceName.equals("HMSoft")) {
  ToastMaster("Connecting you Now !!!");
  connectBT = new ConnectToBluetooth(discoveredDevice);
  new Thread(connectBT).start();
  
  } else { 
  ToastMaster("Please Turn on Target Device");
  ToastMaster("Please Turn on Target Device");
  ToastMaster("Please Turn on Target Device");
  ToastMaster("Please Turn on Target Device");
  ToastMaster("Please Turn on Target Device");
  }
  }
  
  if(BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)){
  ToastMaster("Already CONNECTED with Target Device");
  while(scSocket==null){
  }
  BTisConnected=true;
  if(scSocket!=null){
  sendReceiveBT = new SendReceiveBytes(scSocket);
  new Thread(sendReceiveBT).start();
  String red = "r";
  byte[] myByte = stringToBytesUTFCustom(red);
  sendReceiveBT.write(myByte);
  }
  }
  }
}

// *** for Communication *** //
public static byte[] stringToBytesUTFCustom(String str) {
  char[] buffer = str.toCharArray();
  byte[] b = new byte [buffer.length << 1];
  for (int i = 0; i < buffer.length; i++) {
  int bpos = i << 1;
  b[bpos] = (byte) ((buffer[i]&0xFF00)>>8);
  b[bpos + 1] =(byte) (buffer[i]&0x00FF);
  }
  return b;
}

public void onDestroy() {    
  System.exit(0);
}
  
public class ConnectToBluetooth implements Runnable{
  private BluetoothDevice btShield;
  private BluetoothSocket mySocket = null;
  private UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  
  public ConnectToBluetooth(BluetoothDevice bluetoothShield) {
  btShield = bluetoothShield;
  
  try{
  mySocket = btShield.createRfcommSocketToServiceRecord(uuid);
  }
  catch(IOException createSocketException){
  Log.e("ConnectToBluetooth", "Error with Socket");
  }
  }
  
  public void run() {
  bluetooth.cancelDiscovery();
  
  try{
  mySocket.connect();
  scSocket=mySocket;
  } catch (IOException connectException){
  Log.e("ConnectToBluetooth", "Error with Socket Connection");
  
  try{
  mySocket.close();
  }
  catch(IOException closeException){
  }
  return;
  }
  }

  public BluetoothSocket getSocket() {
  return mySocket;
  }

  public void cancel() {
  try {
  mySocket.close();
  } catch (IOException e) {
  }
  }
}

// *** For GUI Communication *** //
private class SendReceiveBytes implements Runnable {
  private BluetoothSocket btSocket;
  private InputStream btInputStream = null;
  private OutputStream btOutputStream = null;
  String TAG = "SendReceiveBytes";
  public SendReceiveBytes(BluetoothSocket socket) {
  btSocket = socket;
  try {
  btInputStream = btSocket.getInputStream();
  btOutputStream = btSocket.getOutputStream();
  }
  catch (IOException streamError) {
  Log.e (TAG, "Error when getting input or output Stream");
  }
  }
  
  public void run () {
  byte[] buffer = new byte [1024];
  int bytes;
  while (true) {
  try {
  bytes = btInputStream.read(buffer);
  mHandler.obtainMessage (MESSAGE_READ, bytes, -1, buffer)
  .sendToTarget();
  }
  catch (IOException e) {
  Log.e(TAG, "Error reading from btInputStream");
  break;
  }
  }
  }
  
  public void write(byte[] bytes) {  
  try {
  btOutputStream.write(bytes);
  }
  catch (IOException e) {
  Log.e(TAG, "Error when writing to btOutputStream");
  }
  }

  @SuppressWarnings("unused")
  public void cancel() {
  try {
  btSocket.close();
  }
  catch (IOException e) {
  Log.e(TAG, "Error when closing the btSocket");
  }
  }
}

void ToastMaster(String textToDisplay) {
  Toast myMessage = Toast.makeText(this.getActivity().getApplicationContext(),
  textToDisplay,
  Toast.LENGTH_LONG);
  myMessage.setGravity(Gravity.CENTER, 0, 0);
  myMessage.show();
}

Any help would be appreciated.

Thank you

The errors that I get when trying to run your Bluetooth code are primarily string errors. When I get time I will try to debug it for you. Your code will likely run when these are fixed; it does not appear to be a Processing problem. In the meantime, please see if you are able to run this demo; it’s what I use for Android bluetooth communication: https://github.com/vsquared/Processing_Android

Does it still have errors? It did not show errors in my end though. Looking forward for errors in my end.

Thank you

Though those codes worked in processing 3 before.