0

我正在尝试绑定 libuvccamera java 库以访问在 Xamarin.Android 中开发的 Android 设备中的 UVC 摄像头,并且在绑定libuvccamera.aar 和 usbCameraCommon.aar文件期间我遇到了很多麻烦。其中一个是 java.lang.ClassNotFoundException,它在调用 java 类的 USBMonitor 协构函数时被调用:

    USBMonitor usb_monitor; 

    try
    {
        usb_monitor = new USBMonitor(this, this);

    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.WriteLine(ex.StackTrace);
    }

我已经导入了 .arr 库,如此处所述 在此处输入图像描述

但是当我创建分发并将应用程序运行到我的 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

一些建议如何解决这个问题?

谢谢!

4

1 回答 1

0

我已经解决了这个问题。我必须在 .arr 库中实现 HandlerThreadHandler 类,以便 USBMonitor 类的构造函数可以找到它。

于 2021-04-02T14:11:59.953 回答