问题描述
我通过我的Android应用程序加载了一些.dll库,但实际上有关于这个问题的问题很多,但是没有任何一个解决我的问题,以下是我如何实现它们: / p>
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.loadLibrary(NetSDKDLL); //这是我得到的异常
simpleDLL INSTANCE =(simpleDLL)Native.loadLibrary(
(NetSDKDLL),simpleDLL.class);
}
public interface NetSDKDLL扩展StdCallLibrary {
int IP_NET_DVR_RealPlay(NativeLong nLoginId);
}
}
这是日志:
01-29 12:20:34.407:E / AndroidRuntime(1623):致命例外:主
01-29 12:20: 34.407:E / AndroidRuntime(1623):进程:com.example.removed,PID:1623
01-29 12:20:34.407:E / AndroidRuntime(1623):java.lang.UnsatisfiedLinkError:无法加载来自loader的NetSDKDLL dalvik.system.PathClassLoader [DexPathList [[zip file/data/app/com.example.removed-2.apk\"],nativeLibraryDirectories=[/data/app-lib/com.example.removed-2, / system / lib]]]:findLibrary返回null
01-29 12:20:34.407:E / AndroidRuntime(1623):java.lang.Runtime.loadLibrary(Runtime.java:358)
01-29 12:20:34.407:E / AndroidRuntime(1623):java.lang.System.loadLibrary(System.java:526)
01-29 12:20:34.407:E / AndroidRuntime(1623) :at com.example.removed.MainActivity.onCreate(MainActivity.java:34)
并给出一个清晰的概述:
1-我没有问题SDK,它的路径已经在eclipse和系统环境中分配。
2- dll库放在名为 dll 的源文件夹中。
3- dll库也放在 libs 文件夹中。
我在一个常规的Java应用程序中使用相同的方式,它的工作原理很好。
更新:
new例外:
02-01 09:18:44.840:E / AndroidRuntime 1145):引起的:java.lang.UnsatisfiedLinkError:在资源路径(。)中找不到的本地库(com / sun / jna / android-i686 / libjnidispatch.so)
pre>
解决方案您缺少JNA自己的本机支持。请参阅。
请注意,您需要遵循Android的特定规则,以捆绑和加载本地代码与您的应用程序。
编辑
具体来说,您的项目必须包含资源路径>
com / sun / jna /< arch-specific> /libjnidispatch.so
pre>
JNA将在
下寻找 code><拱特异性> /<映射-库名称>
您可以设置系统属性
-Djna.debug_load = true
和
-Djna.debug_load.jna = true
,JNA将分别发送到stdout,它正在寻找你自己的图书馆。 p>
JNA在。
I have a problem loading some .dll libraries through my android app, in fact there is tons of questions about this issue but not any one of them solves my problem, the following is how I'm trying to implement them:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); System.loadLibrary("NetSDKDLL"); // this is where I'm getting the Exception simpleDLL INSTANCE = (simpleDLL) Native.loadLibrary( ("NetSDKDLL"), simpleDLL.class); } public interface NetSDKDLL extends StdCallLibrary { int IP_NET_DVR_RealPlay(NativeLong nLoginId); } }
And this is the log:
01-29 12:20:34.407: E/AndroidRuntime(1623): FATAL EXCEPTION: main 01-29 12:20:34.407: E/AndroidRuntime(1623): Process: com.example.removed, PID: 1623 01-29 12:20:34.407: E/AndroidRuntime(1623): java.lang.UnsatisfiedLinkError: Couldn't load NetSDKDLL from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.removed-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.removed-2, /system/lib]]]: findLibrary returned null 01-29 12:20:34.407: E/AndroidRuntime(1623): at java.lang.Runtime.loadLibrary(Runtime.java:358) 01-29 12:20:34.407: E/AndroidRuntime(1623): at java.lang.System.loadLibrary(System.java:526) 01-29 12:20:34.407: E/AndroidRuntime(1623): at com.example.removed.MainActivity.onCreate(MainActivity.java:34)
And to give a clear overview:
1- I've no problem in SDK and it's path is already assigned in eclipse and in System Environments.
2- the dll libraries are placed in a source folder called dll.
3- the dll libraries also placed in libs folder.
4- I'm using the same way in a regular Java app and it works perfectly.
Updates:
new Exception:
02-01 09:18:44.840: E/AndroidRuntime(1145): Caused by: java.lang.UnsatisfiedLinkError: Native library (com/sun/jna/android-i686/libjnidispatch.so) not found in resource path (.)
解决方案You're missing JNA's own native support. See this question.
Note that you'll need to follow Android's specific rules for bundling and loading native code with your app.
EDIT
Specifically, your project must include the resource path
com/sun/jna/<arch-specific>/libjnidispatch.so
JNA will look for your native libraries under
<arch-specific>/<mapped-library-name>
You can set the system properties
-Djna.debug_load=true
and-Djna.debug_load.jna=true
and JNA will emit to stdout where it's looking for your libraries and its own, respectively.JNA provides the value for
<arch-specific>
in Platform.RESOURCE_PREFIX.这篇关于无法从加载程序加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!