-
Notifications
You must be signed in to change notification settings - Fork 545
Java.Lang.ClassNotFoundException: Didn't find class "<..>" on path: DexPathList #10081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you share more of the code example on how Thanks! |
This is the only call site, public void Play(byte[] data)
{
if (!(data?.Length > 0))
{
return;
}
player.Reset();
player.SetDataSource(new StreamMediaDataSource(data));
player.Prepare();
player.Start();
stopwatch.Restart();
isPlaying = true;
} This is located in a |
Is there some code in |
I'm not sure what that means exactly internal class StreamMediaDataSource(byte[] data) : MediaDataSource
{
public override long Size => data.Length;
public override int ReadAt(long position, byte[]? buffer, int offset, int size)
{
if (position >= data.Length)
return -1;
var toRead = Math.Min(size, data.Length - (int)position);
data.AsSpan((int)position, toRead).CopyTo(buffer.AsSpan(offset, toRead));
return toRead;
}
public override void Close() { }
} |
I had some time to try to repro this, and I found Gerald has a sample using I found the "Stream Audio" button works fine on .NET 10 Preview 4 (unreleased nightly builds): Is this sample similar enough to what you're doing here to cause the problem? |
Here were my changes to target .NET 10: |
Thanks for looking into it. No, it's quite different. Mine is an Avalonia application where the shared and Android "shell" projects are F#. My modified version of Plugin.Maui.Audio is in the same solution and referenced by both projects. Guess I have no other choice but to start whittling the solution down until I have a small enough repro to share. |
Alright, here you go https://github.com/kerams/repro-and When I run When I switch to Preview 2, I get an expected error from the media player itself (input data is garbage). |
Fixes: #10081 Fixes: #10118 Context: 18ca528 Context: dotnet/java-interop@5852e6e dotnet/java-interop@5852e6e3 updated `JniEnviroment.Types.FindClass()` to begin using [`Class.forName(String, bool, ClassLoader)`][0] to load Java types instead of `ClassLoader.loadClass()`. This broke type registration on non-Java threads under NativeAOT; attempting to load a non-Android Java type from a managed thread: var t = new System.Threading.Thread(() => { using var c = new ClassFromThisAssembly(); }); t.Start(); t.Join(); would fail with a `ClassNotFoundException`: E NUnit : Java.Lang.ClassNotFoundException: Didn't find class "from.NewManagedThreadOne" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]] E NUnit : at Java.Interop.JniEnvironment.Types.TryFindClass(String, Boolean) + 0x3f4 E NUnit : at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type) + 0x130 E NUnit : at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type) + 0x94 E NUnit : at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String, Type, JniArgumentValue*) + 0x1c E NUnit : at Java.Lang.Object..ctor() + 0x108 E NUnit : at Java.InteropTests.JnienvTest.<>c__DisplayClass6_0.<RegisterTypeOnNewManagedThread>b__0() + 0x24 E NUnit : --- End of managed Java.Lang.ClassNotFoundException stack trace --- E NUnit : java.lang.ClassNotFoundException: Didn't find class "from.NewManagedThreadOne" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib64, /system_ext/lib64, /system/lib64, /system_ext/lib64]] E NUnit : at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) E NUnit : at java.lang.ClassLoader.loadClass(ClassLoader.java:637) E NUnit : at java.lang.ClassLoader.loadClass(ClassLoader.java:573) Fix this by setting `NativeAotRuntimeOptions.ClassLoader` to the `context.getClassLoader()` value within `NativeAotRuntimeProvider.attachInfo()`. This ensures that we use a `ClassLoader` that knows about the app's `classes.dex`. [0]: https://developer.android.com/reference/java/lang/Class#forName(java.lang.String,%20boolean,%20java.lang.ClassLoader)
Android framework version
net10.0-android (Preview)
Affected platform version
10.0.100-preview.3.25201.16
Description
I'm inheriting from
MediaDataSource
in order to play audio inAndroid.Media.MediaPlayer
from an in-memory mp3.It worked just fine with
10.0.100-preview.2.25164.34
, but with10.0.100-preview.3.25201.16
I now get an exception during the instantiation of this class:If I use global.json to pin the SDK to Preview 2, the problem disappears.
Steps to Reproduce
I failed to reproduce it in an empty project, so at the moment I'm in the dark with respect to what exactly might be the thing that makes a difference.
The text was updated successfully, but these errors were encountered: