20

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=

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

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

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

Li_W
  • 759
  • 1
  • 5
  • 15

2 Answers2

21

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

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/

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/libpdfview2.so).

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

    static
    {
    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:

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

Here are some examples:

private native int parseBytes(byte[] bytes);  
private native int parseFile(String fileName);  
private native int parseFileDescriptor(FileDescriptor fd);  
Theo
  • 5,963
  • 3
  • 38
  • 56
  • That's what I'm trying to do but I couldn't compile that project from C source code. I've managed to extract the compiled library files from the APK, but don't know how to include them into the Android project in Eclipse. – Li_W Dec 28 '11 at 00:07
  • Did you follow the build instructions here? http://code.google.com/p/apv/source/browse/pdfview/jni/build-instructions.txt – Theo Dec 28 '11 at 00:15
  • Yeah it didn't work. I gave up. Those instructions are for building libpdfview2.so, and I have that file extracted from the APK so I don't need help with building the C source. I need help importing / linking that to Android app. – Li_W Dec 28 '11 at 00:37
  • Thanks! Most of those are already done; I have updated the question with the specific error in Eclipse I'm still getting. I have googled it to no avail. – Li_W Dec 28 '11 at 01:04
  • I am using /lib. Going to get some dinner and look at this later. Thanks for your help. – Li_W Dec 28 '11 at 01:09
  • 1
    Works now. I needed to use /libs instead of /lib, as the answer prescribed. Thanks! – Li_W Dec 28 '11 at 03:09
5

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.

Community
  • 1
  • 1
Michi
  • 681
  • 1
  • 7
  • 25