Skip to content
Nuvyntra Labs

Platform integration

Android

AAR with embedded libnuvexa.so for arm64-v8a. Same Kotlin API as desktop.

Overview

Same Kotlin API as the desktop JVM SDK, packaged as an AAR with libnuvexa.so for arm64-v8a (minSdk 26).

1. Download

From NuvexaDB v1.0.6:

Release assetWhat you use
`NuvexaDB-Android.zip`The .aar inside (often android-release.aar). It already embeds jni/arm64-v8a/libnuvexa.so.

You do not need NuvexaDB-Java-*.zip or a separate NUVEXA_NATIVE_LIB on the device. JNA loads nuvexa from the APK.

Optional: NuvexaDB-Native-android-arm64.zip is the raw libnuvexa.so if you assemble the AAR yourself.

x86 emulator images are not a published ABI. Use an arm64 emulator or a physical device.

2. Empty project

In Android Studio: File → New → New Project → Empty Activity (Kotlin, API 26+).

Or:

# Android Studio wizard, or
mkdir AcmeStore && cd AcmeStore
# create an application module named app

3. Add the downloaded package

Copy the AAR to app/libs/android-release.aar. In app/build.gradle.kts:

dependencies {
    implementation(files("libs/android-release.aar"))
    implementation("net.java.dev.jna:jna:5.17.0@aar")
    implementation("org.json:json:20250107")
}

Enable flatDir only if your AGP version requires it for files(...).

4. Create, open, close

import nuventra.nuvexadb.NuvexaDatabase

val path = File(filesDir, "app.nvx").absolutePath
NuvexaDatabase.create(path, key).use { db ->
    // work
}
val opened = NuvexaDatabase.open(path, key)
try {
    // work
} finally {
    opened.close()
}

Use filesDir or noBackupFilesDir, not external storage, so the .nvx stays in the app sandbox.

5. Delete the database

db.close()
File(path).delete()
File("$path-wal").delete()

6. Collections

db.insert("users", """{"name":"Ada","age":36}""")
db.listCollections()
db.renameCollection("users", "people")
db.dropCollection("people")

7. Documents

val id = db.insert("users", """{"name":"Ada","age":36}""")
db.insertMany("users", """[{"name":"Grace","age":85}]""")
val doc = db.findById("users", id)
db.replace("users", """{"_id":"$id","name":"Ada Lovelace","age":36}""")
db.deleteById("users", id)
db.execute("""db.users.find({ age: { ${'$'}gte: 21 } }).limit(20)""")

8. Password for an encrypted file

Do not put the key in BuildConfig or resources. Store it in Android Keystore (or EncryptedSharedPreferences wrapping a Keystore key) and pass that string into create / open. Prompt on first launch if the product is user-held. 1234 is only for a local sample.

db.changeEncryptionKey(currentKey, nextKey)

See Encryption notes.

Discussion

Comment on NuvexaDB. The thread lives on this component's GitHub repository (nuvyntralabs/NuvexaDB). Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.