Xamarin.Android Java 绑定库运行时访问本地库失败
Xamarin.Android Java bindings library runtime failure accessing native library
TL;DR:我正在寻找一种方法来从 Android 设备中查找并提取本机共享库 (.so) 文件,该设备 运行ning 特定于供应商的自定义 Android建造。我需要此文件作为 Xamarin.Android Java 绑定库中缺失的部分。
我正在尝试为 Java SDK 创建一个 Xamarin.Android 绑定库,它在 Famoco 的 Android 设备上公开激光条码扫描 API。这些设备 运行 特定于供应商的 Android 构建,支持一些特殊功能,例如集中式设备管理。
我按照 usual procedures 创建绑定库,没有使用任何自定义转换或添加,也没有编译器错误。
这是在绑定库中生成的工厂方法,它试图创建一个新的 BarCodeReader
实例:
[Register ("open", "(ILandroid/content/Context;)Lcom/zebra/adc/decoder/BarCodeReader;", "")]
public static unsafe global::Com.Zebra.Adc.Decoder.BarCodeReader Open (int readerId, global::Android.Content.Context context)
{
const string __id = "open.(ILandroid/content/Context;)Lcom/zebra/adc/decoder/BarCodeReader;";
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [2];
__args [0] = new JniArgumentValue (readerId);
__args [1] = new JniArgumentValue ((context == null) ? IntPtr.Zero : ((global::Java.Lang.Object) context).Handle);
var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
return global::Java.Lang.Object.GetObject<global::Com.Zebra.Adc.Decoder.BarCodeReader> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
} finally {
}
}
以上代码在执行以下行时失败:
var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
抛出异常:No implementation found for void com.zebra.adc.decoder.BarCodeReader.native_setup(java.lang.Object, int, java.lang.Object)
.
我从 troubleshooting guidelines 了解到,这种类型的失败通常是由于无法解析所需的本机库造成的。
为了确认原因,我使用 JD-GUI 反编译了 Famoco JAR,从中提取了以下实现代码片段:
// This is the underlying Java implementation of the above bindings library factory method
public static BarCodeReader open(int readerId, Context context)
{
return new BarCodeReader(readerId, context);
}
// This is the BarCodeReader constructor that is called by the factory method
BarCodeReader(int readerId, Context context)
{
this.mEventHandler = null;
this.mAutoFocusCallback = null;
this.mDecodeCallback = null;
this.mErrorCallback = null;
this.mPreviewCallback = null;
this.mSnapshotCallback = null;
this.mVideoCallback = null;
this.mZoomListener = null;
Looper aLooper = Looper.myLooper();
if (null == aLooper) {
aLooper = Looper.getMainLooper();
}
if (aLooper != null) {
this.mEventHandler = new EventHandler(this, aLooper);
}
native_setup(new WeakReference(this), readerId, context);
}
// This method is called by the above constructor, but fails because no implementation exists
private final native void native_setup(Object paramObject, int paramInt);
在我看来,上述 运行time 错误的发生是因为私有方法 native_setup
未在 Java 代码中实现,而是在本地库中单独实现未在我的绑定库项目中的任何地方引用。这看起来像是一个合理的诊断吗?
不幸的是,我在 Famoco 提供的 SDK 套件中没有找到任何 .so(本机库)文件。我已经联系了他们的支持团队,他们表示在使用他们的 SDK JAR 时没有必要 link .so 文件。 Famoco 并不热衷于在他们的设备上支持跨平台应用程序,但他们确实确认他们有其他客户使用 Xamarin,他们似乎已经解决了这个问题。不幸的是,Famoco 支持似乎无法告诉我如何实现这一目标。
设备上是否已经存在所需的本机库(作为自定义 Android 构建的一部分部署)?为了验证这个假设,我安装了 Famoco 示例激光扫描应用程序,它 运行 是正确的,即使在其项目源工具包中没有 .so 文件的迹象。
如果是这样,是否可以从Android环境中找到并提取.so文件,我应该怎么做?
是的,libbarcodereader44.so 文件应该预装在自定义设备上。它可能位于 /system/lib 或 /vendor/lib 目录中。在调用 open ()
方法之前,您必须从代码中加载此库。 您可以找到有关 Famoco SDK 的更多详细信息。
TL;DR:我正在寻找一种方法来从 Android 设备中查找并提取本机共享库 (.so) 文件,该设备 运行ning 特定于供应商的自定义 Android建造。我需要此文件作为 Xamarin.Android Java 绑定库中缺失的部分。
我正在尝试为 Java SDK 创建一个 Xamarin.Android 绑定库,它在 Famoco 的 Android 设备上公开激光条码扫描 API。这些设备 运行 特定于供应商的 Android 构建,支持一些特殊功能,例如集中式设备管理。
我按照 usual procedures 创建绑定库,没有使用任何自定义转换或添加,也没有编译器错误。
这是在绑定库中生成的工厂方法,它试图创建一个新的 BarCodeReader
实例:
[Register ("open", "(ILandroid/content/Context;)Lcom/zebra/adc/decoder/BarCodeReader;", "")]
public static unsafe global::Com.Zebra.Adc.Decoder.BarCodeReader Open (int readerId, global::Android.Content.Context context)
{
const string __id = "open.(ILandroid/content/Context;)Lcom/zebra/adc/decoder/BarCodeReader;";
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [2];
__args [0] = new JniArgumentValue (readerId);
__args [1] = new JniArgumentValue ((context == null) ? IntPtr.Zero : ((global::Java.Lang.Object) context).Handle);
var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
return global::Java.Lang.Object.GetObject<global::Com.Zebra.Adc.Decoder.BarCodeReader> (__rm.Handle, JniHandleOwnership.TransferLocalRef);
} finally {
}
}
以上代码在执行以下行时失败:
var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
抛出异常:No implementation found for void com.zebra.adc.decoder.BarCodeReader.native_setup(java.lang.Object, int, java.lang.Object)
.
我从 troubleshooting guidelines 了解到,这种类型的失败通常是由于无法解析所需的本机库造成的。
为了确认原因,我使用 JD-GUI 反编译了 Famoco JAR,从中提取了以下实现代码片段:
// This is the underlying Java implementation of the above bindings library factory method
public static BarCodeReader open(int readerId, Context context)
{
return new BarCodeReader(readerId, context);
}
// This is the BarCodeReader constructor that is called by the factory method
BarCodeReader(int readerId, Context context)
{
this.mEventHandler = null;
this.mAutoFocusCallback = null;
this.mDecodeCallback = null;
this.mErrorCallback = null;
this.mPreviewCallback = null;
this.mSnapshotCallback = null;
this.mVideoCallback = null;
this.mZoomListener = null;
Looper aLooper = Looper.myLooper();
if (null == aLooper) {
aLooper = Looper.getMainLooper();
}
if (aLooper != null) {
this.mEventHandler = new EventHandler(this, aLooper);
}
native_setup(new WeakReference(this), readerId, context);
}
// This method is called by the above constructor, but fails because no implementation exists
private final native void native_setup(Object paramObject, int paramInt);
在我看来,上述 运行time 错误的发生是因为私有方法 native_setup
未在 Java 代码中实现,而是在本地库中单独实现未在我的绑定库项目中的任何地方引用。这看起来像是一个合理的诊断吗?
不幸的是,我在 Famoco 提供的 SDK 套件中没有找到任何 .so(本机库)文件。我已经联系了他们的支持团队,他们表示在使用他们的 SDK JAR 时没有必要 link .so 文件。 Famoco 并不热衷于在他们的设备上支持跨平台应用程序,但他们确实确认他们有其他客户使用 Xamarin,他们似乎已经解决了这个问题。不幸的是,Famoco 支持似乎无法告诉我如何实现这一目标。
设备上是否已经存在所需的本机库(作为自定义 Android 构建的一部分部署)?为了验证这个假设,我安装了 Famoco 示例激光扫描应用程序,它 运行 是正确的,即使在其项目源工具包中没有 .so 文件的迹象。
如果是这样,是否可以从Android环境中找到并提取.so文件,我应该怎么做?
是的,libbarcodereader44.so 文件应该预装在自定义设备上。它可能位于 /system/lib 或 /vendor/lib 目录中。在调用 open ()
方法之前,您必须从代码中加载此库。