无法从加载器加载库 [英] Couldn't load library from loader

查看:269
本文介绍了无法从加载器加载库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过我的Andr​​oid应用程序加载某些.DLL库的一个问题,其实还有吨关于这个问题,但问题不是他们中的任何一个解决我的问题,以下是我正在努力实现它们:

 公共类MainActivity延伸活动{  @覆盖
  保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);    的System.loadLibrary(NetSDKDLL); //这就是我得到异常
    simpleDLL INSTANCE =(simpleDLL)Native.loadLibrary(
            (NetSDKDLL),simpleDLL.class);
  }   公共接口NetSDKDLL扩展StdCallLibrary {
      INT IP_NET_DVR_RealPlay(NativeLong nLoginId);
   }
}

这是日志:

  12月1日至29日:20:34.407:E / AndroidRuntime(1623):致命异常:主要
12月1日至29日:20:34.407:E / AndroidRuntime(1623):工艺:com.example.removed,PID:1623
12月1日至29日:20:34.407:E / AndroidRuntime(1623):java.lang.UnsatisfiedLinkError中:无法从装载机dalvik.system.PathClassLoader [DexPathList [zip文件加载NetSDKDLL \"/data/app/com.example.removed-2.apk\"],nativeLibraryDirectories=[/data/app-lib/com.example.removed-2, /系统/ lib目录]]]:findLibrary返回null
12月1日至29日:20:34.407:E / AndroidRuntime(1623):在java.lang.Runtime.loadLibrary(Runtime.java:358)
12月1日至29日:20:34.407:E / AndroidRuntime(1623):在java.lang.System.loadLibrary(System.java:526)
12月1日至29日:20:34.407:E / AndroidRuntime(1623):在com.example.removed.MainActivity.onCreate(MainActivity.java:34)

和给出一个明确的概述:

1我在SDK中没有问题,它的路径是Eclipse和系统环境。

已分配

2- DLL库放置在一个名为源文件夹中的 DLL

3的DLL库也放在文件夹中。

4-我使用了普通的Java应用程序同样的方式,它完美的作品。


更新:

新的异常:

 九月2日至1日:18:44.840:E / AndroidRuntime(1145):java.lang.UnsatisfiedLinkError中:由造成本机库(COM /阳光/ JNA / Android系统的i686 / libjnidispatch.so)的资源路径未找到(。)


解决方案

您错过JNA自己的原生支持。见<一href=\"http://stackoverflow.com/questions/17346438/exception-in-thread-main-java-lang-unsatisfiedlinkerror-jnidispatch-com-sun/17346812#17346812\">this问题。

请注意,你需要遵循Android的具体规则捆绑和装载本地code。与您的应用程序。

修改

具体来说,您的项目必须包含的资源路径

  COM /阳光/ JNA /&LT;拱特异性的GT; /libjnidispatch.so

JNA将寻找的的下

本机库

 &LT;拱特异性的GT; /&LT;映射库-名称&gt;

您可以设置系统属性 -Djna.debug_load = TRUE
-Djna.debug_load.jna = TRUE 和JNA会散发到stdout在那里的分别寻找你的图书馆和自己。

JNA提供了&LT的价值;拱特异性&GT; 中的 Platform.RESOURCE_ preFIX

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.

这篇关于无法从加载器加载库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆