java.lang.ClassNotFoundException 在 Xamarin.Android 中绑定 java 库
java.lang.ClassNotFoundException binding java library in Xamarin.Android
我正在尝试绑定 libuvccamera java 库以在 Xamarin.Android 中开发的 Android 设备中访问 UVC 相机,并在绑定 libuvccamera.aar and the usbCameraCommon.aar 文件期间我有很多麻烦。其中之一是 java.lang.ClassNotFoundException,当调用 java class:
的 USBMonitor 构造函数时被调用
USBMonitor usb_monitor;
try
{
usb_monitor = new USBMonitor(this, this);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
我已经按照说明导入了 .arr 库 here
但是当我为我的 Android 设备创建分发和 运行 应用程序时,我收到如下异常调用:
Failed resolution of: Lcom/serenegiant/utils/HandlerThreadHandler;
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <94b04e1756104d1fa1d144932ae2720c>:0
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/Android.Runtime/JNIEnv.g.cs:444
at Android.Runtime.JNIEnv.FinishCreateInstance (System.IntPtr instance, System.IntPtr jclass, System.IntPtr constructorId, Android.Runtime.JValue* constructorParameters) [0x00008] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/Android.Runtime/JNIEnv.cs:362
at Com.Serenegiant.Usb.USBMonitor..ctor (Android.Content.Context context, Com.Serenegiant.Usb.USBMonitor+IOnDeviceConnectListener listener) [0x000df] in C:\dev\code\curr\LETTURA_DATA_MATRIX_LUXOTTICA\DEMO\TEST_UVC_CAMERA_LIB\TEST_3\LIBUVC\obj\Debug\generated\src\Com.Serenegiant.Usb.USBMonitor.cs:1076
at TEST_3.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0001e] in C:\dev\code\curr\LETTURA_DATA_MATRIX_LUXOTTICA\DEMO\TEST_UVC_CAMERA_LIB\TEST_3\TEST_3\MainActivity.cs:28
--- End of managed Java.Lang.NoClassDefFoundError stack trace ---
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/serenegiant/utils/HandlerThreadHandler;
at com.serenegiant.usb.USBMonitor.<init>(USBMonitor.java:122)
at crc645ed0f3853a61fd03.MainActivity.n_onCreate(Native Method)
at crc645ed0f3853a61fd03.MainActivity.onCreate(MainActivity.java:44)
at android.app.Activity.performCreate(Activity.java:7957)
at android.app.Activity.performCreate(Activity.java:7946)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3598)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2261)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.serenegiant.utils.HandlerThreadHandler" on path: DexPathList[[zip file "/data/app/com.companyname.test_3-RASdU4LTR0mcU0jXj9KO8Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.test_3-RASdU4LTR0mcU0jXj9KO8Q==/lib/arm, /data/app/com.companyname.test_3-RASdU4LTR0mcU0jXj9KO8Q==/base.apk!/lib/armeabi-v7a, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more
关于如何解决这个问题的一些建议?
谢谢!
我已经解决了这个问题。我必须在 .arr 库中实现 HandlerThreadHandler class,因此 USBMonitor class 的构造函数可以找到它。
我正在尝试绑定 libuvccamera java 库以在 Xamarin.Android 中开发的 Android 设备中访问 UVC 相机,并在绑定 libuvccamera.aar and the usbCameraCommon.aar 文件期间我有很多麻烦。其中之一是 java.lang.ClassNotFoundException,当调用 java class:
的 USBMonitor 构造函数时被调用 USBMonitor usb_monitor;
try
{
usb_monitor = new USBMonitor(this, this);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
我已经按照说明导入了 .arr 库 here
但是当我为我的 Android 设备创建分发和 运行 应用程序时,我收到如下异常调用:
Failed resolution of: Lcom/serenegiant/utils/HandlerThreadHandler;
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <94b04e1756104d1fa1d144932ae2720c>:0
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/Android.Runtime/JNIEnv.g.cs:444
at Android.Runtime.JNIEnv.FinishCreateInstance (System.IntPtr instance, System.IntPtr jclass, System.IntPtr constructorId, Android.Runtime.JValue* constructorParameters) [0x00008] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/Android.Runtime/JNIEnv.cs:362
at Com.Serenegiant.Usb.USBMonitor..ctor (Android.Content.Context context, Com.Serenegiant.Usb.USBMonitor+IOnDeviceConnectListener listener) [0x000df] in C:\dev\code\curr\LETTURA_DATA_MATRIX_LUXOTTICA\DEMO\TEST_UVC_CAMERA_LIB\TEST_3\LIBUVC\obj\Debug\generated\src\Com.Serenegiant.Usb.USBMonitor.cs:1076
at TEST_3.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0001e] in C:\dev\code\curr\LETTURA_DATA_MATRIX_LUXOTTICA\DEMO\TEST_UVC_CAMERA_LIB\TEST_3\TEST_3\MainActivity.cs:28
--- End of managed Java.Lang.NoClassDefFoundError stack trace ---
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/serenegiant/utils/HandlerThreadHandler;
at com.serenegiant.usb.USBMonitor.<init>(USBMonitor.java:122)
at crc645ed0f3853a61fd03.MainActivity.n_onCreate(Native Method)
at crc645ed0f3853a61fd03.MainActivity.onCreate(MainActivity.java:44)
at android.app.Activity.performCreate(Activity.java:7957)
at android.app.Activity.performCreate(Activity.java:7946)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3598)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3775)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2261)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8107)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.serenegiant.utils.HandlerThreadHandler" on path: DexPathList[[zip file "/data/app/com.companyname.test_3-RASdU4LTR0mcU0jXj9KO8Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.test_3-RASdU4LTR0mcU0jXj9KO8Q==/lib/arm, /data/app/com.companyname.test_3-RASdU4LTR0mcU0jXj9KO8Q==/base.apk!/lib/armeabi-v7a, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more
关于如何解决这个问题的一些建议?
谢谢!
我已经解决了这个问题。我必须在 .arr 库中实现 HandlerThreadHandler class,因此 USBMonitor class 的构造函数可以找到它。