0

I am struggling to use a shared library in an Android application.

I've downloaded the jsqlite shared libs and unzipped these into my project to the HelloSpatialite/app/src/main/jniLibs directory. SO posts (example) say this is all you need to do in recent Android Studio versions.

This is my directory listing:

HelloSpatialite/app/src/main/jniLibs]: ls -l /.so

-rwxr-xr-x@ 1 user staff 7778576 Jun 16 22:40 armeabi-v7a/libjsqlite.so

-rwxr-xr-x@ 1 user staff 7782620 Jun 16 22:30 armeabi/libjsqlite.so

-rwxr-xr-x@ 1 user staff 12080476 Jun 16 22:51 x86/libjsqlite.so

I verified the shared library is included in the APK as in step 3 here.

However, now I am not able to use the classes and functions from this library.

If my java code uses an import jsqlite.Database;, I will get an Error:(6, 15) error: package jsqlite does not exist from Android Studio.

I am trying to follow the android-spatialite tutorial. The code example for this tutorial is from the eclipse era and also seems to be getting the jsqlite package in a slightly different way.

Can someone help me get on the right track here?

EDIT: My code, minus the shared objects, is on github.

Community
  • 1
  • 1
fahrradler
  • 141
  • 1
  • 2
  • 9

1 Answers1

0

I finally managed to figure this out.

Since the shared libs were already compiled, I had to keep the corresponding java file namespace at package jsqlite;. The real issue then was to figure out how to keep those java files actually at that top level scope.

I ended up modifying the AndroidManifest.xml for my module to not have the usual "yourcompany.packagename" scoping and instead just used "packagename". The usual:

<manifest
    package="com.example.spatialite_database_driver">
</manifest>

becomes

<manifest
    package="spatialite_database_driver">
</manifest>

I am not sure if this is the most ideal scenario, but it lets my module work without having to get into recompiling the JNI code.

I have the process used to successfully set up this module here: https://github.com/kristina-hager/Spatialite-Database-Driver/blob/master/README.md along with a link to an app using the module.

note: for this module, there are no prepared .jar or .aar files available, so I am using the shared objects + java src files in a module.

fahrradler
  • 141
  • 1
  • 2
  • 9