How do I import a native library (.so file) into Eclipse?

前端 未结 2 1171
耶瑟儿~
耶瑟儿~ 2020-11-28 16:11

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

2条回答
  •  無奈伤痛
    2020-11-28 17:06

    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);  
    

提交回复
热议问题