Hello B4X Community,
This is my first thread ...
While looking for a offline-first db solution for b4a beside cloudkvs I came across this
(https://github.com/sqliteai/sqlite-sync)
As Erel has mentioned in a thread by default, Android OS does not support loading SQLite extensions (such as .so files) the same way as standard desktop SQLite. This means you can’t simply load an extension with load_extension or similar commands out-of-the-box in Android.
Yesterday sqliteai team updated its github and has added a doc for android integration.
This is how they work around it.
SQLite Sync Integration Guide for Android
This guide shows how to integrate SQLite Sync into your Android application. Since extension loading is disabled by default in Android's SQLite implementation, you need an alternative SQLite library that supports extensions.
This example uses the `requery:sqlite-android` library, but other options include building a custom SQLite with extension support or using other third-party SQLite libraries that enable extension loading.
1. Add Dependencies
In your `app/build.gradle.kts`:
2. Bundle the Extension
Place your `cloudsync.so` file in:
`app/src/main/assets/lib/cloudsync.so`
3. Basic Integration
Can anyone help me in converting above solution for b4a?
My goals are:
- Synchronize a local SQLite database on an Android device with a remote database/server using sqlite-sync.
Has anyone successfully used sqlite-sync with B4A? If so:
- Could you share sample code, libraries, or wrapper suggestions?
- Are there any B4A-specific caveats or things to watch out for? YES I know about Cloudkvs & Wmsynctable by walt61.
Here is the .aar file for requery sqlite android for wrapping
https://repo1.maven.org/maven2/io/requery/requery-android/1.6.0/
Greetings.
This is my first thread ...
While looking for a offline-first db solution for b4a beside cloudkvs I came across this
(https://github.com/sqliteai/sqlite-sync)
As Erel has mentioned in a thread by default, Android OS does not support loading SQLite extensions (such as .so files) the same way as standard desktop SQLite. This means you can’t simply load an extension with load_extension or similar commands out-of-the-box in Android.
Yesterday sqliteai team updated its github and has added a doc for android integration.
This is how they work around it.
SQLite Sync Integration Guide for Android
This guide shows how to integrate SQLite Sync into your Android application. Since extension loading is disabled by default in Android's SQLite implementation, you need an alternative SQLite library that supports extensions.
This example uses the `requery:sqlite-android` library, but other options include building a custom SQLite with extension support or using other third-party SQLite libraries that enable extension loading.
1. Add Dependencies
In your `app/build.gradle.kts`:
Code:
dependencies {
implementation("com.github.requery:sqlite-android:3.49.0")
}
2. Bundle the Extension
Place your `cloudsync.so` file in:
`app/src/main/assets/lib/cloudsync.so`
3. Basic Integration
Java:
import android.content.Context
import androidx.activity.ComponentActivity
import androidx.lifecycle.lifecycleScope
import io.requery.android.database.sqlite.SQLiteCustomExtension
import io.requery.android.database.sqlite.SQLiteCustomFunction
import io.requery.android.database.sqlite.SQLiteDatabase
import io.requery.android.database.sqlite.SQLiteDatabaseConfiguration
import io.requery.android.database.sqlite.SQLiteFunction
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream
class MainActivity : ComponentActivity() {
private fun copyExtensionToFilesDir(context: Context): File {
val assetManager = context.assets
val inputStream = assetManager.open("lib/cloudsync.so")
val outFile = File(context.filesDir, "cloudsync.so")
inputStream.use { input ->
FileOutputStream(outFile).use { output ->
input.copyTo(output)
}
}
return outFile
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Copy extension from assets to filesystem
val extensionFile = copyExtensionToFilesDir(this)
val extensionPath = extensionFile.absolutePath
// Create extension configuration
val cloudSyncExtension = SQLiteCustomExtension(extensionPath, null)
// Configure database with extension
val config = SQLiteDatabaseConfiguration(
"${filesDir.path}/test.db",
SQLiteDatabase.CREATE_IF_NECESSARY or SQLiteDatabase.OPEN_READWRITE,
emptyList<SQLiteCustomFunction>(),
emptyList<SQLiteFunction>(),
listOf(cloudSyncExtension)
)
// Open database
val db = SQLiteDatabase.openDatabase(config, null, null)
// Test extension loading
lifecycleScope.launch {
withContext(Dispatchers.IO) {
val cursor = db.rawQuery("SELECT cloudsync_version();", null)
val version = if (cursor.moveToFirst()) cursor.getString(0) else null
cursor.close()
if (version != null) {
println("SQLite Sync loaded successfully. Version: $version")
Can anyone help me in converting above solution for b4a?
My goals are:
- Synchronize a local SQLite database on an Android device with a remote database/server using sqlite-sync.
Has anyone successfully used sqlite-sync with B4A? If so:
- Could you share sample code, libraries, or wrapper suggestions?
- Are there any B4A-specific caveats or things to watch out for? YES I know about Cloudkvs & Wmsynctable by walt61.
Here is the .aar file for requery sqlite android for wrapping
https://repo1.maven.org/maven2/io/requery/requery-android/1.6.0/
Sorry for directly quoting you guys
@DonManfred
@Johan Schoeman
@Daestrum
@drgottjr
@teddybear
@JordiCP
@DonManfred
@Johan Schoeman
@Daestrum
@drgottjr
@teddybear
@JordiCP
Greetings.
Last edited: