Creating a product SDK: How do I add a native lib (.so) and a jar with the SDK I am creating?

后端 未结 4 1713
别那么骄傲
别那么骄傲 2020-11-30 03:18

I am creating a widget that we will provide to developer end users and it consists of a .jar and a native library (.so) built using the NDK. The JA

4条回答
  •  渐次进展
    2020-11-30 03:34

    Using ADT 12, I accomplished this by doing the following:

    1) Export JAR from your library with the SO file using Eclipse. Make sure you exclude AndroidManifest.xml. This will include source code and other data, so if you are distributing, you'll want to strip these unnecessary bits out using any ZIP utility.

    2) Create a directory in your App's source tree (I use "lib" directory) and copy your library JAR to it.

    3) Right-click project in Eclipse and select "Configure Build Path". Add JAR and point it to JAR inside your App source tree.

    4) In your Eclipse preferences, select Android/Build section and uncheck "Automatically refresh Resources and Assets folder on build". You will notice an option below that says "Force error when external jars contain native libraries." There is an ADT bug, which will supposedly be fixed in R17, which uses the wrong setting. Once it is fixed, you will use the "Force error" one (make sure it unchecked).

    5) Once you build your app APK, you will have a libs/armeabi/libXXXX.so file. This will not be automatically unpacked on install. You will need to write code to extract it from your APK file into your data directory, then use System.load on the .so file in your data directory.

    I have bidirectional JNI calls going from the dynamically loaded file, and even use dlopen() on it to do my custom plugin registration stuff.

提交回复
热议问题