如何将本机库(.so 文件)导入 Eclipse? [英] How do I import a native library (.so file) into Eclipse?

查看:36
本文介绍了如何将本机库(.so 文件)导入 Eclipse?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了 Android PDF 查看器源代码并尝试在 Eclipse 中编译它.我的朋友说我可以直接从 APK 中提取预编译的 .so 文件,而不是搞乱 Cygwin 并重新编译本机 C 库:

I downloaded the Android PDF Viewer source code and am trying to compile it in Eclipse. Instead of messing with Cygwin and recompiling the native C libraries, my friend said I can just extract the pre-compiled .so files from the APK here:

http://code.google.com/p/apv/downloads/detail?name=apv-0.3.1dev13.apk&can=2&q=

我究竟如何将这些 libpdfview2.so 文件导入到 eclipse 项目中?

How exactly do I import these libpdfview2.so files into the eclipse project?

更新:Eclipse 出现以下错误并且无法运行:

Updated: Eclipse gives the following error and will not run:

所需库的存档:项目APV"中的lib/armeabi/libpdfview2.so"无法读取或不是有效的 ZIP 文件

Archive for required library: 'lib/armeabi/libpdfview2.so' in project 'APV' cannot be read or is not a valid ZIP file

推荐答案

看看他们是如何在示例项目中设置的: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);  

这篇关于如何将本机库(.so 文件)导入 Eclipse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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