且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将本机库(.so 文件)导入 Eclipse?

更新时间:2023-11-17 12:18:34

看看他们是如何在示例项目中设置的:http://code.google.com/p/apv/source/浏览/#hg%2Fpdfview

See how they set things up in the sample project: http://code.google.com/p/apv/source/browse/#hg%2Fpdfview

这个 NDK 教程在帮助您了解 NDK 的工作方式方面也可能很有用:http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/一个>

This NDK tutorial may also be useful in terms of helping you figure out how things work with the NDK: http://mobile.tutsplus.com/tutorials/android/ndk-tutorial/

基本原理是:

  1. .so 库文件通常位于 project_root_dir/libs 子文件夹中.此外,通常它们位于描述其架构的其他子文件夹中(例如 project_root_dir/libs/armeabi/libpdfview2.so).

  1. The .so library files typically go in the project_root_dir/libs subfolder. Also, generally they are in further subfolders that describe their architecture (e.g. project_root_dir/libs/armeabi/libpdfview2.so).

要在活动中使用库,请向活动添加静态库加载器,如下所示:

To use the library in an activity you add a static library loader to the activity as shown below:

静态
{
System.loadLibrary("pdfview2");//注意缺少 lib 前缀
}

static
{
System.loadLibrary("pdfview2"); // Notice lack of lib prefix
}

然后定义要导入的本机函数.您可以通过 native 关键字识别这些函数.查看下面的文件,看看它们在示例中导入了哪些函数:

You then define the native functions you are importing. You can recognize these functions thanks to the native keyword. Look in the file below to see what functions they import in the sample:

http://code.google.com/p/apv/source/browse/pdfview/src/cx/hell/android/pdfview/PDF.java?r=560343d2dad904c5c925b6cadf97b90430fd25f4

以下是一些示例:

private native int parseBytes(byte[] bytes);  
private native int parseFile(String fileName);  
private native int parseFileDescriptor(FileDescriptor fd);