simolus3 / sqlite3.dart

sqlite3 bindings for Dart
MIT License
222 stars 74 forks source link

libsqlite3.so not found #70

Open mprogers opened 2 years ago

mprogers commented 2 years ago

I've got a nice-looking app running on macOS and iOS, but I am having a whole lot of difficulty with the Android version: I'm getting this error:

Invalid argument(s): Failed to load dynamic library
'/data/data/com.example.great_app_v1/lib/libsqlite3.so': dlopen
failed: library
"/data/data/com.example.great_app_v1/lib/libsqlite3.so" not found

My dependencies are: flutter: sdk: flutter sqlite3: ^1.4.0

I also tried these dependencies:

dependencies: flutter: sdk: flutter sqlite3: ^1.4.0 provider: ^6.0.0

cupertino_icons: ^1.0.2 fl_chart: ^0.40.6 sqlite3_flutter_libs: ^0.5.2

import 'package:sqlite3_flutter_libs/sqlite3_flutter_libs.dart'

But then I get this error: SqliteException(14): bad parameter or other API misuse, bad parameter or other API misuse (code 21)

Ah, it might be because it can't find the location of the .sqlite file itself. I'll keep digging ...

simolus3 commented 2 years ago

Depending on sqlite3_flutter_libs should be enough.

If you get SqliteException(14): bad parameter or other API misuse, bad parameter or other API misuse (code 21), sqlite3 has already been loaded successfully - it's just throwing an exception. Can you post the trace of that exception? If it happens when creating a new database file, it might be that the parent directory doesn't exist? (You need to create it with dart:io first).

AndreLuizNogueira commented 3 weeks ago

I just had this issue on android 14, were you using sqlcipher_flutter_libs? I removed cypher to resolve it, but I wanted cypher back.

tp commented 1 week ago

Depending on sqlite3_flutter_libs should be enough.

@simolus3 Just for my understanding: Why is sqlite3_flutter_libs needed on Android?

For me this also fixed using sqlite3, but I was surprised I needed it in the first place. I assumed it would just use the Android-bundled SQLite version by default.

I suppose add sqlite3_flutter_libs does not hurt the other platforms (Apple and Windows for us), but on the other hand it might save some app size not shipping our own bundled version.

simolus3 commented 1 week ago

Just for my understanding: Why is sqlite3_flutter_libs needed on Android?

Because (since Android 6) we can't dlopen('libsqlite3.so') on Android. The Android-bundled SQLite version is only available through the Java APIs, not via the NDK / dart:ffi.