android – How do I import a native library (.so file) into Eclipse?-ThrowExceptions

Exception or error:

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:

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

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

Archive for required library: ‘lib/armeabi/’ in project ‘APV’ cannot be read or is not a valid ZIP file

How to solve:

See how they set things up in the sample project:

This NDK tutorial may also be useful in terms of helping you figure out how things work with the NDK:

The basics are this:

  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/

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

    System.loadLibrary(“pdfview2”); // Notice lack of lib prefix

  3. 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:

Here are some examples:

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


As mentioned another Stack Overflow thread about this topic switching off “Automatically refresh Resources and Assets folder on build” and “Force error when external jars contain native libraries” under Window/Preferences/Android/Build helps. At least it helped in my case!

And don’t forget to put the so-file in ‘lib s/armeabi’ to have it availible at runtime.

Hope this helped others, also if it was too late for Li_W.

Leave a Reply

Your email address will not be published. Required fields are marked *