How to locate my Android SDK in Processing 4.3?

When I opened an Android sketch was asked to download or locate the SDK. Download automatically didn’t work. So I did the manual download using:
https://android.processing.org/tutorials/getting_started/
and I ran the sdkmanager:

Now I have directories like:
cmdline-tools
licenses
platform-tools
platforms

I’ve tried to point the SDK to different directories without luck. Any advice would be appreciated.

Windows 11, Prcoessing 4.3

Hi @bigboss97.
If you are using the most recent version of Android mode it will not work on Windows currently.
I’ve reported the bug here: Error in line #408 AndroidSDK.java with Windows · Issue #768 · processing/processing-android · GitHub
You have to use an older version for now. Due to Gradle issues with older versions I gave up and instead used Android Studio. There is a tutorial here on that here, Processing for Android

Thanks, I’ll install Android Studio and give it a try.
I’ve tried to locate the command-line tool with Processing v4.1.1 and v4.3.

I’ve installed Android Studio. But I can’t find Java in language. What have I missed?

@bigboss97, what you are referring to is just the language Gradle uses for the build scripts. Gradle (Android’s build tool) will only use Kotlin or Groovy. Android projects can use Java or Kotlin. It’s confusing, but you shouldn’t have to interact with your build scripts very much. To use Java create a new java file by right-clicking on the …/src/main/java folder and select New → Java Class. I hope that helps get you started.

I’m totally new in Android Studio. Maybe I just wait for the fix or…
According to #768, v4.5.1 would work. Do I have to build it myself?

You can find old releases of Android mode here, Releases · processing/processing-android · GitHub
You can download the files under “Assets” and manually install it by placing the folder in your “modes” folder.
Android mode 4.5.1 doesn’t have the Windows issue with installing or locating the SDK so it may work. But I still had issues with Gradle and couldn’t build a sketch, which is probably a compatibility issue with Gradle 7 and 8. But I gave up and used Android Studio instead.

I’ve downloaded the demo project. After a lot of fiddling around, I finally got something running on my Galaxy Z Flip:


After launch, the app disappears to the task list and I can’t activate it. There’s no error message either. What can I try?

Hi @bigboss97. Check the LogCat (the cat image on left) to see if there are any errors or warnings. If so post those here. Also, do you have public void onRequestPermissionsResult() in your MainActivity?
I don’t know if this is the problem but you don’t need the public void settings() method at all. It should default to full screen.
Also, it wasn’t entirely clear, are running on an emulator or the device?

LogCat

FATAL EXCEPTION: main
Process: androidstudio.tutorials, PID: 7579
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{androidstudio.tutorials/androidstudio.tutorials.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "androidstudio.tutorials.MainActivity" on path: DexPathList[[dex file "/data/data/androidstudio.tutorials/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~or4zcKFQnuNshzrxOJgdeg==/androidstudio.tutorials-4RSLdCus4fJDrbNtaXq9SA==/base.apk"],nativeLibraryDirectories=[/data/app/~~or4zcKFQnuNshzrxOJgdeg==/androidstudio.tutorials-4RSLdCus4fJDrbNtaXq9SA==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4066)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4340)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2584)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:226)
	at android.os.Looper.loop(Looper.java:313)
	at android.app.ActivityThread.main(ActivityThread.java:8810)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidstudio.tutorials.MainActivity" on path: DexPathList[[dex file "/data/data/androidstudio.tutorials/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~or4zcKFQnuNshzrxOJgdeg==/androidstudio.tutorials-4RSLdCus4fJDrbNtaXq9SA==/base.apk"],nativeLibraryDirectories=[/data/app/~~or4zcKFQnuNshzrxOJgdeg==/androidstudio.tutorials-4RSLdCus4fJDrbNtaXq9SA==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
	at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
	at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:44)
	at android.app.Instrumentation.newActivity(Instrumentation.java:1339)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4053)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4340) 
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) 
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2584) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:226) 
	at android.os.Looper.loop(Looper.java:313) 
	at android.app.ActivityThread.main(ActivityThread.java:8810) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) 

MainActivity.java

public class MainActivity extends AppCompatActivity {
  private PApplet sketch;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout frame = new FrameLayout(this);
    frame.setId(CompatUtils.getUniqueViewId());
    setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                     ViewGroup.LayoutParams.MATCH_PARENT));

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

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

  @Override
  public void onNewIntent(Intent intent) {
    if (sketch != null) {
      sketch.onNewIntent(intent);
    }
    super.onNewIntent( intent);
  }
}

I’ve added super.xyz() because the compiler was complaining.

I’m launching via USB to my Galaxy z flip (Android 13).

@bigboss97, that’s not a fun error to get , :anguished:
This could be several things,
Here is a link to several solutions to a similar problem, java - Android ClassNotFoundException: Didn't find class on path - Stack Overflow
It could also be a conflict between the name of your package in the AndroidManifest.xml, look at this, Android ClassNotFoundException: Didn't find class on path - Stack Overflow
I’m sure it’s a simple fix but can’t know without your full project.

@robertesler, thank you so much for your help :+1: I placed the two *.java files in the right location and updated package accordingly. Now it’s working, hooray!

I’ve written a note for myself and thought that might be useful for someone else, too.
Following steps are based on the instruction and using Android Studio Koala 2024.1.1

  1. New project: Empty Views Activity
    Package name: androidstudio.audiotest
    Language: Java
  2. Copy processing-core.jar to app/libs
  3. File → Project Structure → Dependencies
    add JAR: libs/processing-core.jar
  4. Copy MainActivity.java & Sketch.java to app/src/main/java/androidstudio/audiotest

MainActivity.java

package androidstudio.audiotest;

import android.os.Bundle;
import android.content.Intent;
import android.view.ViewGroup;
import android.widget.FrameLayout;
//import android.support.v7.app.AppCompatActivity;

import androidx.appcompat.app.AppCompatActivity;

import processing.android.PFragment;
import processing.android.CompatUtils;
import processing.core.PApplet;

public class MainActivity extends AppCompatActivity {
  private PApplet sketch;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FrameLayout frame = new FrameLayout(this);
    frame.setId(CompatUtils.getUniqueViewId());
    setContentView(frame, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                     ViewGroup.LayoutParams.MATCH_PARENT));

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

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

  @Override
  public void onNewIntent(Intent intent) {
    if (sketch != null) {
      sketch.onNewIntent(intent);
    }
    super.onNewIntent( intent);
  }
}

Sketch.java

package androidstudio.audiotest;

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

The above project has nothing to do with audio. It’s just my test project :grin:

1 Like