-->

Adding “.so” library to my android studio project

2019-07-10 14:43发布

问题:

I am having issues when i try to add a spatialite database to my android studio projet.I followed this tutorial https://www.gaia-gis.it/fossil/libspatialite/wiki?name=spatialite-android-tutorial , as mentioned i added two folders to my project :

  1. the native spatialite libraries: they are places in a folder named libs in my App directory and contains several folders for different platforms that hold the main library, called libspatialite.so

  2. the basic API classes, contained in the jsqlite package

Despite this ,i am getting this error :

11-13 13:52:17.358    1853-1853/liara.geodatamining W/System.err﹕ Unable to load sqlite_jni: java.lang.UnsatisfiedLinkError: Couldn't load proj from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/liara.geodatamining-2.apk"],nativeLibraryDirectories=[/data/app-lib/liara.geodatamining-2, /system/lib]]]: findLibrary returned null
11-13 13:52:17.358    1853-1853/liara.geodatamining W/dalvikvm﹕ No implementation found for native Ljsqlite/Database;.internal_init:()V
11-13 13:52:17.358    1853-1853/liara.geodatamining W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Ljsqlite/Database;
11-13 13:52:17.358    1853-1853/liara.geodatamining W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb2d19b20)
11-13 13:52:17.358    1853-1853/liara.geodatamining E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: liara.geodatamining, PID: 1853
    java.lang.UnsatisfiedLinkError: Native method not found: jsqlite.Database.internal_init:()V
            at jsqlite.Database.internal_init(Native Method)
            at jsqlite.Database.<clinit>(Database.java:951)
            at liara.geodatamining.map.onCreate(map.java:116)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)  

Am i missing something ?

回答1:

This sounds a lot like you haven't included the appropriate version of the NDK for your emulator. Per the Android docs, the following platforms support Android NDK

  • ARM
  • ARM-NEON
  • x86
  • MIPS

The most common by far for real devices is ARM (armeabi-v7a). In fact, it's probably almost no loss to not include anything except for this for a published build. But the emulators often work off of x86. I know I have a NDK file for x86 that I remove every time I'm ready to build for release, and re-add when I want to use my desktop emulator.



回答2:

if you're only using .so files and not compiling any C/C++ sources yourself, you don't need the NDK.

With Android Studio, the place where you drop .so files isn't the same than with eclipse. Now it's inside jniLibs/<ABI> where ABI can be armeabi, armeabi-v7a, x86, x86_64, mips, mips64, arm64-v8a.

You can check that your .so files are properly integrated by opening your APK as a zip file and simply checking that your .so files are inside lib/<abi> folders.