This project provides prebuilt Spatialite extensions for Android that can be used with SQLite to add spatial data support to your applications. The Spatialite library (version 5.0.0) has been cross-compiled using the Android NDK for multiple architectures to support different Android devices.
Spatialite is a powerful spatial extension for SQLite that enables spatial/GIS functionality. However, the official Spatialite library does not provide direct support for Android platforms. This project bridges that gap by cross-compiling the Spatialite source code using the Android NDK, making it possible to use spatial functions in SQLite on Android devices.
As the developer, I personally wanted a reliable way to load Spatialite extensions into op-sqlite for React Native projects, which led to the forking of this repository with prebuilt binaries specifically for this purpose.
The project supports multiple Android architectures:
- ARM64 (arm64-v8a)
- ARMv7 (armeabi-v7a)
- x86
- x86_64
- Android NDK installed
- Android API level 13 or higher
cd jni
# i used version 27.3.13750724 , replace with whatever version you have
export ANDROID_NDK_HOME=~/Android/Sdk/ndk/27.3.13750724
export ANDROID_NDK_ROOT=$ANDROID_NDK_HOME
ndk-build clean
ndk-buildThe prebuilt artifacts are located in the /libs directory with separate folders for each supported Android architecture:
libs/
├── arm64-v8a/
│ └── libspatialite.so
├── armeabi-v7a/
│ └── libspatialite.so
├── x86/
│ └── libspatialite.so
└── x86_64/
└── libspatialite.so
To confirm that they have the correct symbols
nm -D libs/x86/libspatialite.so | grep sqlite3_modspatialite_init# Output:
009d5cd0 T sqlite3_modspatialite_initTo use the prebuilt Spatialite extension with op-sqlite in your React Native project:
- Place the appropriate
libspatialite.sofiles in your Android project'slibsfolder - Use the following code to load the extension:
import { open } from "@op-engineering/op-sqlite";
const opsqliteDb = open({
name: "myDB",
});
const path = "libspatialite";
opsqliteDb.loadExtension(path, "sqlite3_modspatialite_init");This will enable all Spatialite functions in your SQLite database, allowing you to perform spatial queries like:
SELECT ST_AsText(geometry_column) FROM your_table;
SELECT ST_Distance(point1, point2) FROM your_table;- Spatialite Version: 5.0.0
- Host Platform: Ubuntu 20.04 (x86_64 architecture)
- Target Platform: Android API 13 (arm64-v8a and other architectures)
- Build Status: Successful builds for all supported architectures (as of latest commit: d1c482f7)
The library is compiled using the Android NDK from the original Spatialite source code. The build process includes several dependencies to provide full Spatialite functionality:
- GEOS (Geometry Engine - Open Source)
- PROJ (Cartographic Projections Library)
- libxml2
- JSON-C
- Iconv
- LZMA/XZ support