【问题标题】:dlopen("xxxx") failed: dlopen failed: library "xxxx" not founddlopen(“xxxx”)失败:dlopen 失败:找不到库“xxxx”
【发布时间】:2015-06-18 08:14:38
【问题描述】:
package com.test.nativeapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    static {
        try {
            System.load("native/libkdu_jni.so");
        } catch (UnsatisfiedLinkError e) {
          System.err.println("Native code library failed to load.\n" + e);
          System.exit(1);
        }
      }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

LogCat 错误:

06-18 11:13:55.235: D/dalvikvm(17658): 试图加载 lib 本机/libkdu_jni.so 0x421eeb38 06-18 11:13:55.235: E/dalvikvm(17658): dlopen("native/libkdu_jni.so") 失败:dlopen 失败:库 未找到“native/libkdu_jni.so”

06-18 11:13:55.235: W/System.err(17658): 本机代码库未能 加载。

06-18 11:13:55.235:W/System.err(17658): java.lang.UnsatisfiedLinkError:dlopen 失败:库 未找到“native/libkdu_jni.so”

我应该把这个文件夹放在哪里?

【问题讨论】:

  • 你能展示你的项目结构吗?
  • 为什么要打开 XXX 库? ;) Pr0n..

标签: java android


【解决方案1】:

试试这个:

System.loadLibrary("kdu_jni");

loadLibrary() 实际上是从猿的 lib/ 加载的。此外,您不需要指定“lib”和扩展名“so”。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我对其他 .so 文件也有同样的问题。 我使用相关文件将 jniLibs 库添加到 ...src/main 并且它有效。 也许你可以试试。

    【讨论】:

      【解决方案3】:

      使用System.load("…");,您正在以一种无法被构建系统的 Android APK 打包代码检测到的方式加载库。因此,该库不包含在 APK 中,并且在您在 Android 设备上启动应用程序时无法在运行时找到。

      要解决这个问题,请使用构建系统的机制让 APK 打包器知道要包含的额外库。这在构建系统之间会有所不同。例如,在 CMake 构建系统中,您只需将库添加到 target_link_libraries(…) 中的库列表中:

      add_executable(my_executable_name ${SRCS} ${RESOURCES})
      
      # Link all required libraries with the executable, 
      # and include them into the Android APK.
      target_link_libraries(my_executable_name
          # Name libraries here as you would when calling "g++ -l…".
          # Alternatively, use absolute paths.
          Qt5::Core
          Qt5::Quick
          /my/path/to/native/libkdu_jni.so
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多