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:55.235: E/dalvikvm(17658):dlopen (“本机/libkdu_jni.so”)失败:dlopen failed: library“本机/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 failed:库“本机/libkdu_jni.so”未找到
我应该把这个文件夹放在哪里?
发布于 2016-07-19 00:28:30
试试这个:
System.loadLibrary("kdu_jni");loadLibrary()实际上从ape的lib/加载。此外,您不需要指定'lib‘&扩展'so’。
希望这能有所帮助。
发布于 2016-11-27 17:20:53
我对其他.so文件也有同样的问题。我将jniLibs库与相关的文件一起添加到...src/main中,它起了作用。也许你可以试试。
发布于 2020-06-10 16:26:41
使用System.load("…");,您正在以构建系统的Android打包代码无法检测到的方式加载库。因此,这个库不包含在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
)https://stackoverflow.com/questions/30909922
复制相似问题