geopaparazzi / libjsqlite-spatialite-android

Project to create the libjsqlite.so used in geopaparazzi
75 stars 24 forks source link

Example (Current) "hello world" usage of this library / libjsqlite? #12

Closed kristina-hager closed 6 years ago

kristina-hager commented 9 years ago

Hi there, I'm hoping to use spatialite on android for a school project. I have some experience developing android apps. However, I've never used this sort of library before in android.

Do you know of any recent, simple, android app using these libraries? I've been digging through the geopaparazzi app source/structure lately, but I am not having luck imitating that apps setup since it is so complex. I've found some simpler examples such as android-spatialite, but those are using a very old spatialite version and also an old Android development environment.

Most online articlces indicate that to use an 'android library' you should have some .jar or .aar file. I've not managed to find such a thing for as recent spatialite/android as is here. I have tried just adding the 'libjsqlite.so' directly to an app with no luck. Lately, I am trying to use the libjsqlite.so and the SQLite java sources to create an android module, also with no luck.

Or do you have any tips on how to set up a hello world example with these libs? Btw, I am perfectly willing to take on the effort to create such a hello world example to go with these libs and make it open source of course. However, I could just use some help getting started.

mj10777 commented 9 years ago

Do you know of any recent, simple, android app using these libraries?

  • no, although there are many that report using it
  • but I have seen no results

I've been digging through the geopaparazzi app source/structure lately, but I am not having luck imitating that apps setup since it is so complex.

  • very true

One of the major goals 2 (or 3) years ago was get

This is about 85% complete, but there are still portions referencing other library's

The worst problem is however the dependency of the actual painting of the geometry results

If these were spitted into a

Then in the application

        dataOverlay = new ArrayGeopaparazziOverlay(this);
        List<Overlay> overlays = mapView.getOverlays();
        overlays.clear();
        overlays.add(dataOverlay);

could be adapted to add a second overlay, something in the form of:

SpatialiteOverlay geomOverlay=new SpatialiteOverlay;
overlays.add(geomOverlay);

This could be a default painting of the geometries offered by geopaparazzispatialitelibrary

With this geopaparazzispatialitelibrary would be a good 90% self contained, which was the main goal


In a nutshell (possibly not complete):


end of part 1

mj10777 commented 9 years ago

Or do you have any tips on how to set up a hello world example with these libs?

Im Prinzip ja ...


A non Radio Eriwan answer would be:

Create a new Library

Copy the libs of geopaparazzispatialitelibrary.

Copy the src/jsqlite of geopaparazzispatialitelibrary.

Study the use of

Database dbSpatialite;
dbSpatialite = new jsqlite.Database();
try 
{
 dbSpatialite.open(databasePath, jsqlite.Constants.SQLITE_OPEN_READWRITE | jsqlite.Constants.SQLITE_OPEN_CREATE);
}

At this point you have a connection where


All of these can be used to study the use of jsqlite.Database.


end of part 2

mj10777 commented 9 years ago

After getting the basic jsqlite.Database working correctly

which would add the functionality


Hope this helps

mj10777 commented 9 years ago

I am perfectly willing to take on the effort to create such a hello world example to go with these libs and make it open source of course.

This would be welcomed and I would gladly add this to the repository

kristina-hager commented 9 years ago

Hi Mark, Thanks so much for your detailed reply!

I have followed your instructions and put together a couple of GIT repositories showing progress thus far. e.g. https://github.com/kristina-hager/Spatialite-Database-Driver https://github.com/kristina-hager/HelloToSpatialite/tree/master

The issue I'm having is one I've encountered repeatedly already. I have made some brute force attempts to address them without any luck yet.

Namely, I have put the jsqlite source here: Spatialite-Database-Driver/spatialite-db-driver/src/jsqlite in imitation of geopaparazzi. The namespace for those files remains 'package jsqlite'.

I have put the shared objects here: Spatialite-Database-Driver/spatialite-db-driver/libs

I have set up 'HelloToSpatialite' to depend on the library 'Spatialite-Database-Driver'.

However, I am having trouble using jsqlite code in: HelloToSpatialite/app/src/main/java/pimp/hellotospatialite/GeoDatabaseHandler.java. Specifically, I cannot find the right import statement for that file. I've tried import jsqlite of course, but that is marked an error by the Android Studio IDE.

I have also (in other projects, not published) tried putting the jsqlite source down in the HelloToSpatialite/app/src/main/java/pimp/ path. That seemingly helps because I can now do an import pimp.spatialite_database_driver.jsqlite.Database in GeoDatabaseHandler.java which is recognized as valid. Btw, in this case I have changed the package from package jsqlite to pimp.spatialite_database_driver.jsqlite. However, the IDE complains about Cannot resolve corresponding JNI function for private native functions. Some searches on StackOverflow lead me to believe that this is because the namespace of the source changed.

I have also tried the above move of the source while keeping the namespace at package jsqlite;, but that of course doesn't work either.

Therefore, I feel very stuck! I don't know how geoparazzi manages to successfully declare and use the global 'jsqlite' package, or how I can convince my app and library to mimic the same.

mj10777 commented 9 years ago

I am not an expert on the android (java) projects, since they are quite different than 'normal' projects.

As far as I remember, since a apk package must include everything it uses

So you create a new project, with some sort of command


This was how geopaparzzi (before gradle) was created


You have made 2 projects

This may be the cause of your problems.

kristina-hager commented 9 years ago

Hi Mark, Thanks again for your prompt response! I really appreciate it.

I also have an example here: https://github.com/kristina-hager/hello-world-spatialite where the "spatialite-android-library" with jsqlite in it is included within the app. I have the same problem here actually as in the separate libs. Specifically, I can't use import jsqlite in https://github.com/kristina-hager/hello-world-spatialite/blob/master/app/src/main/java/com/example/kristina/hellospatialite/GeoDatabaseHandler.java

Btw, the reason I have tried to set up the spatialite/android as a separate lib is to improve portability of the lib, e.g. make it easier for someone else to use it. I have updated my projects to test whether the separate library is working. E.g. I added https://github.com/kristina-hager/Spatialite-Database-Driver/blob/master/spatialite-db-driver/src/main/java/pimp/spatialite_database_driver/FunConstants.java to the library. I used it in HelloToSpatialite at https://github.com/kristina-hager/HelloToSpatialite/blob/master/app/src/main/java/pimp/hellotospatialite/GeoDatabaseHandler.java At least the IDE is not complaining about the usage of FunConstants so far :)

kristina-hager commented 9 years ago

Hi Mark, Just a quick and very happy update:

I have managed to get my Spatialite lib and app project compiling, running, and echoing out the spatialite component versions as in the tutorial!

I basically had to do some fidgeting with the library component to get the app component to recognize it.

Here's the repositories: https://github.com/kristina-hager/Spatialite-Database-Driver https://github.com/kristina-hager/HelloToSpatialite with a minimal README. I will keep updating 'HelloToSpatialite' java and the README's this weekend.

Thanks so much for your conversation and help thus far! I'm super happy to have gotten this far after fidgeting with Android Studio for hours.

mj10777 commented 9 years ago

I have quickly browsed through both projects and the results look promising.

At this point, however, I would strongly suggest the following

The goal should be that a


The next step would be to apply this logic to the present

Here the main problem will be

If I can get a running version, with these changes made

Afterwhich I will attempt to create and apply

At that point, to my knowledge

An attempt to create a spatialite_database_handler could then be made.

I assume that a major portion will be renaming the structure

Since spatialite (from 'eu.geopaparazzi.spatialite')

should be renamed to


If you could get that working

If successful

kristina-hager commented 9 years ago

Hi Mark, I will take some steps to move my documentation from the readme to the wiki this week.

For today and tomorrow, I am going to look into the map rendering following the examples in drawFromSpatialite(). I did get a chance to check out the rasterlite2_styles branch of geopapparazzi.

Thanks again

mj10777 commented 9 years ago

I have just committed (in the rasterlite2_styles branch), what I believe to be, a workable version of

Both of these should be completely independent of of the other libraries


An Application wishing to use this must fulfill certain conditions

mj10777 commented 9 years ago

It has been decided

If you have made a copy in the mean time



It would also be interesting to see if a

kristina-hager commented 9 years ago

It has been decided to withdraw the changes made in the rasterlite2_styles branch until a more precise decision as to what this should entail has been made

Well, it looks like I took a day off at a very unfortunate time! I was really hoping that these changes would make it easier/possible to use the very well developed code like SpatialVectorTable.java and it's friends.

Can I ask you to elaborate a little more on this decision and what, if any, the overall goals are on making components of geopapparazzi reusable?

And if I can help in any way? The app I am hoping to make would need a notable portion of the functionality that is already implemented in geopaparazzispatialitelibrary. I would far rather expend effort helping to make this component reusable than to write my own code doing similar things. After all, any code I wrote in such a short period of time would surely do much less good of a job!

moovida commented 9 years ago

Hi @kristina-hager , I am afraid that is kind of my fault. Only kind of, since geopaparazzi was not designed to create apps out of the context it was created for. I explained everything a bit better here: https://github.com/geopaparazzi/geopaparazzi/issues/281#issuecomment-138790636

To do what you want to needs more time to make a clean split, and at the moment we do not have the resources to do that. Also I think I am the only one who knows thee complete codebase well enough to make this happen without breaking everything by introducing memory leaks and endless code duplication. Since in the past I accepted code contributions that then kept me working on fixing for days, I am now a bit more careful.

I am not completely sure why you can't also use the geopaparazzi library as base, which has everything needed, but I had no time to read through the discussion which I am grateful Mark answered you.

kristina-hager commented 9 years ago

Hi @moovida and @mj10777 , As always, thanks so much for your responses.

I have tried to just include the geopaparazzilibrary and geopaparazzispatialitelibrary as modules in a project. I can get the project to compile, but I am having problems at runtime. The message is a bit cryptic, so it's not easily debugged (for me anyway).

I've decided to regroup a bit and do some more investigation into how to mix and match both POJO (plain old java) and Android libraries together in an Android app. I am still relatively new to Android/java development, so I hope these simple investigations may illustrate for me what is needed to set up dependency relationships between separate components.

After my 'hello world' work on modules, I will work on this:

It would also be interesting to see if a spatialite_database_driver.jar so only that needed to be included in another project and then make a new HelloToSpatialite using that jar. I will check back with this thread when I get that done.

Once that is done, I may come back to the geopaparazzi code and see if I can figure out how to reuse any code in there. My app needs only a subset of geopaparazzi functionality. Specifically, I want to be able to render a map from a spatialite database source and associate that map with the users current location. Zoom and pan would also be nice features. After some investigation into the code, helped by @mj10777, I was specifically hoping to use classes like SpatialVectorTable and SpatialDatabaseHandler (and their dependencies) from geopaparazzispatialitelibrary. My initial thought was that I'd need to make my own SpatialDatabasesManager for my own (much simpler) purposes.

kristina-hager commented 9 years ago

Hi @mj10777 , I have finally managed to put together a jar of the spatiate android JNI libs: https://bintray.com/kristina-hager/kh-examples/spatialite-android/1.0.0/view#files

This is an example using it: https://github.com/kristina-hager/hello-spatialite-jar

and here is the code that builds and promotes the jar: https://github.com/kristina-hager/spatialite-android-database-driver

I still need to clean up some hard coding in the spatialite-android/build.gradle in the last project. Also, I am quite sure the version '1.0.0' is not right. However, I wanted to get some feedback on this before getting into too much formality here. If this code works out, then I would assume the ownership of the jar build would go into this repository and not mine!

I also don't suspect this project is currently using gradle, but perhaps the gradle aspect could be integrated in anyway?

mj10777 commented 9 years ago

I am afraid, that I have completely neglected you in this matter

kristina-hager commented 9 years ago

Hi Mark, I did manage to get a basic hello world example working as I documented above. I also managed to get spatialite for android packaged into a JAR. It is far simpler, of course, for a developer to work with a JAR than to work with the individual pieces of Spatialite for Android. Additionally, using a JAR promotes reusability of this library especially as the Android IDE evolves.

Do you think you or anyone else would be interested in distributing Spatialite for Android as a JAR?

I am not sure if you, geopaparazzi, or someone else is the owner/maintainer of Spatialite for Android / Spatialite at this point. I would also be willing to help in whatever way I can. For instance, I could work w/ the geopaparazzi repo to modify it to use the JAR and perhaps with libjsqlite to see if I can get that codebase to create a JAR. It would be ideal to distribute this JAR under the proper name/ownership at JCenter and get it properly signed and versioned.

manishmanipal123 commented 7 years ago

Hi kristina-hager Great Work done by you as far the spatiallite jar is concerned.Really appreciate your work as it made life simpler for guys like us who have never worked on NDKs. Thanks a Ton.