Android SQLite R-Tree - How to install a module?

http://www.sqlite.org/rtree.html says that the r * tree is "included as part of the merge, but disabled by default" and enable it ", just compile using the C-preprocessor macro SQLITE_ENABLE_RTREE defined by"

Well, I want to use R-trees in my Android application, but obviously SQLite is pre-installed, etc. Is there a way to enable it on a user phone / device?

As an alternative, is it possible to use NDK and freely available source code for SQLite?

+5
source share
4 answers

You can fully compile your own version of SQLite. We do this to enable encryption / codec modules from wxSQLite. Take a look at the SQLite source in the Android Git repository. Basically, it is just as simple to create Android.mk with parameters (e.g. SQLITE_ENABLE_RTREE) that you want to include. Of course, this will give you a native library. To use it, you need to access it from the NDK or create a wrapper (again, you can look at the Android repository and the Java / JNI shell on SQLite)

+2
source

This worked for me, extract from the Android.mk file. It is intended for spatial spatial expansion of sqlite.

include $(CLEAR_VARS)
# -DOMIT_GEOS=0
# ./configure --build=x86_64-pc-linux-gnu --host=arm-linux-eabi
LOCAL_MODULE    := spatialite
LOCAL_CFLAGS    := -D__ANDROID__ -Dfdatasync=fsync -DOMIT_GEOCALLBACKS -DSQLITE_ENABLE_RTREE
LOCAL_LDLIBS    := -llog 
LOCAL_C_INCLUDES := \
    libiconv-1.13.1/include \
    libiconv-1.13.1/libcharset/include \
    geos-3.2.2/source/headers \
    geos-3.2.2/capi \
    proj-4.6.1/src
LOCAL_SRC_FILES := \
    ./libspatialite-amalgamation-2.4.0/spatialite.c \
    ./libspatialite-amalgamation-2.4.0/empty.cpp \
    ./libspatialite-amalgamation-2.4.0/sqlite3.c
LOCAL_STATIC_LIBRARIES := iconv proj geos
include $(BUILD_STATIC_LIBRARY)
+1
source

https://www.sqlite.org/android/doc/trunk/www/index.wiki SQLite NDK/JNI.

, LOCAL_CFLAGS += -DSQLITE_ENABLE_RTREE jni/sqlite/Android.mk, R-Tree.

SQLite .

+1

2017

  • sqlite-android-xxxxx.aar
  • .aar .zip
  • Android Studio ( ++)
  • // Import.JAR/.AAR Package
  • , ""
  • Android Studio : / . ( "" ), "", " SQLite-android-xxxxx"
  • SQLite : System.loadLibrary( "sqliteX" );
  • SQlite org.sqlite.database.sqlite.xxxxxx
  • onCreate :

    System.loadLibrary("sqliteX");
    
    // get the SQLite version
    String query = "select sqlite_version() AS sqlite_version";
    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(":memory:", null);
    Cursor cursor = db.rawQuery(query, null);
    String sqliteVersion = "";
    if (cursor.moveToNext()) {
        sqliteVersion = cursor.getString(0);
    }
    
    // do some R*Tree things (this will fail for the standard SQLite)
    db.execSQL("CREATE VIRTUAL TABLE demo_index USING rtree(id, minX, maxX, minY, maxY);");
    db.execSQL("INSERT INTO demo_index VALUES(1,-80.7749, -80.7747, 35.3776, 35.3778);");
    db.execSQL("INSERT INTO demo_index VALUES(2,-81.0, -79.6, 35.0, 36.2);");
    
    cursor = db.rawQuery("SELECT id FROM demo_index WHERE minX>=-81.08 AND maxX<=-80.58 AND minY>=35.00  AND maxY<=35.44;", null);
    
    int id = -1;
    if (cursor.moveToFirst()) {
        do {
            id = cursor.getInt(0);
        } while (cursor.moveToNext());
    }
    db.close();
    

( ):

0

All Articles