How to build shared library from static libraries NDK

101 views
Skip to first unread message

VaK

unread,
Apr 27, 2022, 7:12:57 AM4/27/22
to SpatiaLite Users

I have read similar questions to this but none of the answer provided worked.

I want to build a shared library for android to link with JNI, all libraries on which it depends are static libraries. I used this to build spatialite and sqlite for android : https://github.com/geopaparazzi/libjsqlite-spatialite-android/wiki/spatialite-5.0.0.mk .

My makefile for the module looks like this :



include $(CLEAR_VARS)
 LOCAL_MODULE := libosm_to_spatialite

 LOCAL_C_INCLUDES := \
$(SQLITE_PATH) \
 $(SPATIALITE_PATH) \
 $(SPATIALITE_PATH)/src/headers \
$(SPATIALITE_PATH)/src/topology \
 $(XML2_PATH)/include \
 $(XML2_PATH)

 LOCAL_SRC_FILES := \
spatialite_osm_overpass.c

LOCAL_STATIC_LIBRARIES := \
libxml2 \
sqlite \
spatialite

include $(BUILD_SHARED_LIBRARY)

The build stops because none of the included header files are found in spatialite_osm_overpass.c. I have tried to add APP_MODULES := sqlite spatialite xml2 in my Application.mk but it doesn't work.

I have also tried to build this library as a static library by setting APP_MODULES := osm_to_spatialite but the .a is not generated.

can somebody check if my code is correct ? alternatively, how can i generate a .a to link with JNI ?

VaK

unread,
Apr 28, 2022, 10:35:47 AM4/28/22
to SpatiaLite Users
my sqlite.mk looks like this,
everything is good normally, I don't understand....

LOCAL_MODULE    := sqlite

# SQLite flags copied from ASOP
common_sqlite_flags := \
 -DHAVE_USLEEP=1 \
 -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \
 -DSQLITE_THREADSAFE=1 \
 -DNDEBUG=1 \
 -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \
 -DSQLITE_HAS_COLUMN_METADATA=1 \
 -DSQLITE_DEFAULT_AUTOVACUUM=1 \
 -DSQLITE_TEMP_STORE=3 \
 -DSQLITE_ENABLE_FTS3 \
 -DSQLITE_ENABLE_FTS3_BACKWARDS \
 -DSQLITE_ENABLE_RTREE=1 \
 -DSQLITE_DEFAULT_FILE_FORMAT=4

LOCAL_CFLAGS    += $(common_sqlite_flags)

# LOCAL_LDLIBS is always ignored for static libraries
# LOCAL_LDLIBS    := -llog
LOCAL_SRC_FILES += $(SQLITE_PATH)/sqlite3.c
LOCAL_C_INCLUDES += $(SQLITE_PATH)
LOCAL_EXPORT_C_INCLUDES := $(SQLITE_PATH)

LOCAL_STATIC_LIBRARIES :=

include $(BUILD_STATIC_LIBRARY)

iulian

unread,
May 2, 2022, 7:37:19 AM5/2/22
to SpatiaLite Users
see https://github.com/iulian0512/android-spatialite/tree/spatialite5  and if you dont want to build it yourself just use  implementation 'com.github.iulian0512:android-spatialite:2.0.7'  in build.gradle, enjoy.

Asim Ahmad

unread,
Jul 14, 2023, 7:36:02 AM7/14/23
to SpatiaLite Users
Hello,

I successfully build this repository on Ubuntu.

The .so files I got are libandroid_spatialite.so and libc++_shared.so, but no mod_spatialite.so file.

I want to use the virtual routing module in an Android application.

Anyone, to please guide me?
Reply all
Reply to author
Forward
0 new messages