android-spatialite


Source link: https://github.com/sevar83/android-spatialite

android-spatialite

WHAT IS THIS?

  • The Spatialite database ported for Android
  • 100% offline, portable and self-contained as SQLite.

WHEN DO I NEED IT?

  • When you need deployment, collecting, processing and fast querying of small to huge amounts of geometry data (points, polylines, polygons, multipolygons, etc.) on Android devices.
  • When you want to be 100% independent from any server/cloud backend.

GETTING STARTED

If you know basic SQLite, there's almost nothing to learn. The API is 99% the same as the Android SQLite API (as of API level 15). The main difference is the packaging. Use org.spatialite.database.XYZ instead of android.database.sqlite.XYZ and org.spatialite.XYZ instead of android.database.XYZ. Same applies to the other classes - all platform SQLiteXYZ classes have their Spatialite versions.

Gradle

  1. Have this in your project's build.gradle:
allprojects {

repositories {

  ...
  maven {
 url "https://jitpack.io" 
}

}
 
}
 
  1. Add the following to your module's build.gradle:
compile 'com.github.sevar83:android-spatialite:2.0.0' 

EXAMPLE CODE

There is a very simple and useless example in the app module. Another example is the SpatiAtlas experiment.

HOW IT WORKS?

Works the same way as the platform SQLite. It's accessible through Java/JNI wrappers around the Spatialite C library. The Spatialite wrappers were derived and adapted from the platform SQLite wrappers (the standard Android SQLite API).

Other FAQ

What is Spatialite?

Simply: Spatialite = SQLite + advanced geospatial support.
Spatialite is a geospatial extension to SQLite. It is a set of few libraries written in C to extend SQLite with geometry data types and many SQL functions above geometry data. For more info: https://www.gaia-gis.it/gaia-sins/

Does it use JDBC?

No. It uses cursors - the suggested lightweight approach to access SQL used in the Android platform instead of the heavier JDBC.

64-bit architectures supported?

Yes. It builds for arm64-v8a and x86_64. mips64 is not tested.

Reducing the APK size.

This library is distributed as multi-architecture AAR file. By default Gradle will produce a universal APK including the native .so libraries compiled for all supported CPU architectures. Usually that's unacceptable for large libraries like this. But that's easily fixed by using Gradle's "ABI splits" feature. The following gradle code will produce a separate APK per each architecture. The APK size is reduced few times.

android {

  splits {

abi {

 enable true

  reset()

  include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"

 
}

}

  
}
 
}
 

What libraries are packaged currently?

  • SQLite 3.15.1
  • Spatialite 4.3.0a
  • GEOS 3.4.2
  • Proj4 4.8.0
  • lzma 5.2.1
  • iconv 1.13
  • xml2 2.9.2
  • freexl 1.0.2

REQUIREMENTS

Min SDK 15

MIGRATION TO 2.0+

  1. Remove calls to SQLiteDatabase.loadLibs(). Now it is automatically done.
  2. Replace all occasions of import org.spatialite.Cursor; with import android.database.Cursor;
  3. Replace all occasions of import org.spatialite.database.SQLite***Exception; with import android.database.sqlite.SQLite***Exception;

CHANGES

2.0.0

  • Now using the Requery.io SQLite wrapper instead of SQLCipher's. This results to:
  • Android Nougat (25+) supported. The native code no more links to private NDK libraries exception and warning messages similar to UnsatisfiedLinkError: dlopen failed: library "libandroid_runtime.so" not found should be no more. For more details: https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk;
  • Much cleaner codebase derived from a much newer and more mature AOSP SQLite wrapper snapshot;
  • Now possible to build with the latest NDK (tested on R14);
  • Switched to CLang as the default NDK toolchain;
  • 64-bit build targets (arm64-v8a, x86_64);
  • SQLiteDatabase.loadLibs() initialization call is not required anymore;
  • Removed org.spatialite.Cursor interface. Used 'android.database.sqlite.Cursor' instead.
  • Removed the SQLiteXyzException classes. Their AOSP originals are used instead;
  • Dropped support for Android localized collation. SQL statements with "COLLATE LOCALIZED" will cause error. This is necessary to reduce the library size and ensure N compatibility;
  • Updated SQLite to 3.15.1;
  • Updated lzma to 5.2.1;
  • Updated FreeXL to 1.0.2;

CREDITS

The main ideas used here were borrowed from:

KNOWN PROJECTS USING THIS LIBRARY

LICENSE

Apache License 2.0

Resources

A TextView library that allows the user to increase/decrease font size with a two finger gesture by the user.

ShPref is an Android library created to simplify interaction with Shared Preferences.

This library supported pull refresh load more and also supported Radio multi-select Mode. You can design yourself BottomView.

A smooth and silky signature pad for android.

Verso - Offline Reverse Geocode.

Helper classes to build Android Apps through MVP pattern in a faster way.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes