如何从 Xamarin Android 调用 .so 文件的方法?

问题描述:

我有一个来自 Android 驱动程序制造商的 .so 文件.他们提供了一个 Java 示例.问题是我的应用程序是在 Xamarin Android 中开发的.是否可以从 Xamarin 调用 .so 文件的方法?

I have a .so file from an Android driver manufacturer. They provide an example in Java. The problem is that my app is developed in Xamarin Android. Is it possible to call methods of a .so file from Xamarin?

1.在你的项目中创建一个lib文件夹

1.Create a lib folder in your project

2.在其下为平台创建额外的子文件夹:armeabi、armeabi-v7a 等

2.Under that create additional subfolders for the platform: armeabi, armeabi-v7a etc.

3.将您的 .so 文件添加到适当的目录.确保将它们设置为键入 AndroidNativeLibrary 或任何类型.

3.Add your .so files to the appropriate directory. Make sure they are set to type AndroidNativeLibrary or whatever it is.

4.为要调用的 c 函数创建 p/invoke 签名.

4.Create p/invoke signatures for the c functions you want to call.

5.调用这些函数.

注意:您的 .so 文件应该是有效的 EFL 可执行文件.这意味着它们应该针对 Android 设备中的 ARM 处理器进行编译.为此,您应该使用 Android NDK 编译它们

Note: Your .so files should be valid EFL executables. It means they should be compiled for ARM processor in Android Devices. In order to do this, you should compile them with Android NDK

祝你好运!