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

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

问题描述

我下载了Android PDF Viewer源代码,并尝试在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/browse/#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:

static

{

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天全站免登陆