ClassNotFoundException for JuceSharingContentProvider

Running an Android app with a JUCE dynamic library built with 5.4.4 (develop at 937991) I get the following runtime error:

 JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.roli.juce.JuceSharingContentProvider$ProviderCursor" ...

Content Sharing is set to Disabled in Projucer.

The latest known tag that works for me is version 5.4.2 (not tried 5.4.3 yet)

Are you seeing this when building a standard JUCE GUI project on Android or is it only when linking against a JUCE .dll from a non-JUCE app? I can’t reproduce it building the DemoRunner on the latest develop tip.

I am seeing it when linking a JUCE dll from a non-JUCE Android app.

DemoRunner runs fine.

I can confirm that 5.4.3 does not exhibit this problem.

What SDK version are you targeting?

Can you try with the following commit and see if it’s been fixed?

Target SDK version is 26. I will try your commit and report back, thanks!

@ed95 Do I need to recompile Projucer and resave?

Just a re-save should be fine.

1 Like

OK, slightly different error this time - looks like it’s having trouble loading the byte code?

Unable to load dex file: java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]
java.io.IOException: Bad range


JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.roli.juce.JuceSharingContentProvider" on path: DexPathList[[...]]
1 Like

Just hit this issue again after blindly updating the JUCE version for the project…

I am also getting this though the application continues to run

 2019-11-04 02:48:38.753 15407-15407/com.yourcompany.newproject1 E/System: Unable to load dex file: java.nio.HeapByteBuffer[pos=0 lim=0 cap=0]
2019-11-04 02:48:38.755 15407-15407/com.yourcompany.newproject1 E/System: java.io.IOException: Bad range
        at dalvik.system.DexFile.createCookieWithArray(Native Method)
        at dalvik.system.DexFile.openInMemoryDexFile(DexFile.java:366)
        at dalvik.system.DexFile.<init>(DexFile.java:107)
        at dalvik.system.DexPathList.makeInMemoryDexElements(DexPathList.java:291)
        at dalvik.system.DexPathList.<init>(DexPathList.java:105)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:117)
        at dalvik.system.InMemoryDexClassLoader.<init>(InMemoryDexClassLoader.java:35)
        at dalvik.system.InMemoryDexClassLoader.<init>(InMemoryDexClassLoader.java:46)
        at java.lang.Runtime.nativeLoad(Native Method)
        at java.lang.Runtime.doLoad(Runtime.java:1099)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1014)
        at java.lang.System.loadLibrary(System.java:1657)
        at com.roli.juce.Java.<clinit>(Java.java:9)
        at com.roli.juce.Java.initialiseJUCE(Native Method)
        at com.roli.juce.JuceApp.onCreate(JuceApp.java:13)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1120)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5826)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1685)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:176)
        at android.app.ActivityThread.main(ActivityThread.java:6651)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
2019-11-04 02:48:38.758 15407-15412/com.yourcompany.newproject1 I/zygote64: Do partial code cache collection, code=30KB, data=18KB
2019-11-04 02:48:38.759 15407-15412/com.yourcompany.newproject1 I/zygote64: After code cache collection, code=30KB, data=18KB
2019-11-04 02:48:38.759 15407-15412/com.yourcompany.newproject1 I/zygote64: Increasing code cache capacity to 128KB
2019-11-04 02:48:38.820 15407-15407/com.yourcompany.newproject1 W/ResourceType: No package identifier when getting name for resource number 0x00000000
2019-11-04 02:48:38.836 15407-15407/com.yourcompany.newproject1 I/JUCE: JUCE v5.4.5

I’m also getting these errors after updating to 5.4.5, have you found a fix yet?

No, I’m still on 5.4.3 (or 5.4.2 I forget). Had to patch it with a recent fix for Android 10, so would be good to get it fixed so I don’t have to keep a fork of JUCE.

1 Like

I’ve just updated the bytecode for the JuceSharingContentProvider class again on develop, can you see if it’s fixed the issue for you? You’ll need to build the Projucer from the tip of develop and then re-save your project.

1 Like

Thanks @ed95 I’ll try it out and report back.

@ed95 looks like this issue is now fixed on develop, Thank you! :tada:

1 Like

I just got this error after linking JUCE 5.4.5 as a static library to a non-JUCE Android app. Does anyone have tips for dealing with this issue?

My full error message was:
JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException: Didn't find class "com.roli.juce.JuceSharingContentProvider" on path: DexPathList[[zip file "/data/app/com.oculus.sdk.vrinput-2/base.apk"],nativeLibraryDirectories=[/data/app/com.oculus.sdk.vrinput-2/lib/arm64, /data/app/com.oculus.sdk.vrinput-2/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]

Some context of how I got here:
I’m making an Oculus VR app for Android and I want to access some JUCE code, particularly OSC Messaging functionality. My project specifically needs a static library as opposed to a dynamic library due to the default configuration of the Oculus SDK. I want to link a static .a JUCE library for my applications’ native C++ code to use.

When building the default JUCE Static library project from the Projucer in Android Studio, it was difficult for me to find the static library (.a) file that was produced. In the Builds/Android/lib/build/outputs folder, the only thing that seemed to be built was an .aar file which I think is an Android static library, but I was hoping to get a regular static library .a file. I then checked Builds/Android/lib/build/intermediates/cmake/... and found the various .a files corresponding to the static libraries for different build configurations. I also had to find the static library which JUCE depends on, libcpufeatures.a in the folder Builds/Android/lib/.cxx/cmake/…`. (It feels awkward/wrong that I am accessing the static libraries in this way, so if someone knows a more correct way, I would love to hear.)

For my VR app, I manually linked the two static libraries successfully, but I ended up with the runtime error listed above.

I would appreciate any tips here as I am new to Android and best library linking practices.

Thanks!

Have you built the Projucer from the latest develop and re-saved the project?

I have not tried the latest develop branch with fresh Projucer build, but I’ll attempt that today. I did find mention of JuceSharingContentProvider in the file modules/juce_core/native/java/README.txt.

To build my project, I never followed any of the steps in this README which explain how to turn some JUCE Java classes into dex byte code. I noticed my error references “dex” byte code. Should I be following these README steps to get rid of my error? Or, has this already been done automatically for me for classes such as JuceSharingContentProvider?