Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption Example - libsqlite3.so not found #2973

Closed
andyyapwl opened this issue Apr 27, 2024 · 2 comments
Closed

Encryption Example - libsqlite3.so not found #2973

andyyapwl opened this issue Apr 27, 2024 · 2 comments

Comments

@andyyapwl
Copy link

andyyapwl commented Apr 27, 2024

hi, i tried to flutter run the examples/encryption in my android emulator but got the below error:

I/flutter (13408): Error loading data: Invalid argument(s): Failed to load dynamic library '/data/data/com.example.drift_encryption_sample/lib/libsqlite3.so': dlopen failed: library "/data/data/com.example.drift_encryption_sample/lib/libsqlite3.so" not found

below is my pubspec.yaml:
dependencies:
sqflite: ^2.3.0
drift_sqflite: ^2.0.1
drift: ^2.0.2+1
sqlcipher_flutter_libs: ^0.6.0
flutter:
sdk: flutter
path_provider: ^2.0.11
path: ^1.8.1
sqlite3: '>=1.8.0 <3.0.0'

I noticed the package sqlcipher_flutter_libs will not generate libsqlite3.so into the build folder..

@simolus3
Copy link
Owner

Thanks for the report! In that example, we're using this to override how we open sqlcipher:

open
..overrideFor(OperatingSystem.android, openCipherOnAndroid)
..overrideFor(
OperatingSystem.linux, () => DynamicLibrary.open('libsqlcipher.so'))
..overrideFor(
OperatingSystem.windows, () => DynamicLibrary.open('sqlcipher.dll'));

Problematically, we're also using NativeDatabase.createInBackground, which uses a background isolate to manage the database connection. As isolates don't share global variables, the behavior didn't get applied. I've fixed this in a1af6f6114960caaee6a9d7699e27f92cc8c93dc, the solution is to move the setup code into isolateSetup.

@andyyapwl
Copy link
Author

andyyapwl commented Apr 28, 2024

Thank you for your prompt response! The 'libsqlite3.so' error has been resolved, but I encountered a new error on the Android emulator:

SqliteException(26): while executing, file is not a database, file is not a database (code 26)
Causing statement: select count(*) from sqlite_master,

My cipher_version is 4.5.7 community.

Upon investigation, I discovered that changing the database name from 'File(p.join(path.path, 'app.db.enc'))' to 'File(p.join(path.path, 'app.db.sqlite'))' resolves the issue. It appears that the database file was previously created but not encrypted due to the 'libsqlite3.so not found' error. After updating the isolateSetup code, it attempted to encrypt the existing database file, leading to the 'file is not a database' error. This error occurs because we can only encrypt a new database file, not an existing one.

I extracted the 'app.db.sqlite' file from the Android emulator and opened it with SQLiteStudio successfully. I was able to open the database file using the SQLCipher type with a password.

I was stuck on this issue for three days, but your revised code and explanation saved my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants