Android上的DllNotFoundException

Android上的DllNotFoundException

本文介绍了Android上的DllNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Unity中加载共享库.它可以在Windows/Editor上运行,但不能在Android上运行,无论我做什么或用于库,我总是会收到DllNotFoundException.

I'm trying to load shared libraries in Unity. It works on Windows/Editor but not on Android, whatever I do or use for libraries I always get the DllNotFoundException.

我正在使用lib.so文件,这些文件用于32BIT ARM EABIS,因此跨平台编译似乎可以成功.

I am using lib.so files, those are for 32BIT ARM EABIS, so the cross platform compilation seems to succeed.

我的lib.so文件位于Assets/Plugins/Android/libs/armeabis-v7a/文件夹中.

my lib.so files are in the Assets/Plugins/Android/libs/armeabis-v7a/ folder.

我为DllImport尝试了不同的语法(假设lib称为Plugin,文件Plugin.dll和libPlugin.so):

I tried different syntax for DllImport (assuming the lib is called Plugin, and the files Plugin.dll and libPlugin.so) :


[DllImport("Plugin")] => works for Windows only
[DllImport("libPlugin.so")] => obviously wont work for Windows, but doesn't work for Android either.

如果我使用winrar打开.apk,则libs在libs/armeabis-v7a文件夹中.

If I open the .apk with winrar, libs are in the libs/armeabis-v7a folder.

我用于测试的智能手机是带有armv8处理器的OnPlus3.

The smartphone I use for my tests is an OnPlus3 with a armv8 processor.

有人成功在Android上成功加载了共享的本机库吗?关于我在做什么错的任何想法吗?

Anyone managed to sucessfuly load a shared native library on Android ? Any ideas about what I'm doing wrong ?

谢谢

插件代码可以在这里找到: https://github.com/FFmpeg/FFmpeg

plugin code can be found here : https://github.com/FFmpeg/FFmpeg

C#代码可在此处找到: https://github.com/Ruslan-B/FFmpeg.AutoGen/blob/7e001dde3acaad70ed188b75e686f23574f81388/FFmpeg.AutoGen/FFmpegInvoke.cs

C# code can be found here : https://github.com/Ruslan-B/FFmpeg.AutoGen/blob/7e001dde3acaad70ed188b75e686f23574f81388/FFmpeg.AutoGen/FFmpegInvoke.cs

在Unity项目中添加FFmpegInvoke.cs或生成FFmpeg.Autogen.dll并将其添加到项目中都会得到相同的结果(dll只会使Unity项目的构建速度更快).

Adding FFmpegInvoke.cs in the Unity Project or generating the FFmpeg.Autogen.dll and adding it to the project gives the same result (dll just makes the Unity Project faster to build).

推荐答案

我注意到您做错了几件事:

I noticed few things you are doing wrong:

应该在:

Assets/Plugins/Android/libs/armeabi-v7a

如果您具有x86架构版本的插件,则应将其放在以下位置:

If you have the x86 architecture version of the plugin,you should place them at:

Assets/Plugins/Android/libs/x86

这些都不是正确的.如果插件文件名为"libPlugin.so" ,则应使用"Plugin" 作为名称.

None of those are correct. If the plugin file name is "libPlugin.so", you should use "Plugin" as the name.

  • 请勿包含lib前缀.
  • 不包括".so"后缀.

同样,如果插件名称为"libVideoPlayer.so" ,则必须使用"VideoPlayer" . "lib"和".so"被删除.别的都行不通.

Again, if the plugin name is "libVideoPlayer.so", you have to use "VideoPlayer". The "lib" and ".so" are removed. Nothing else will work.

最后一个注意事项是,对于Android C ++插件,您无需导出该插件.例如,不需要DLLExport __declspec(dllexport).

One final note for you, for Android C++ plugin, you do not need to export the plugin. For example, DLLExport __declspec(dllexport) is not necessary.

尽管如此,您必须将函数名称放在"extern "C""内

Although, you must put the function name inside "extern "C""

这篇关于Android上的DllNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 06:13