Open MichaelDark opened 10 months ago
Hopefully, the upcoming native-assets feature will fix this by giving us full control over the libraries we want to link.
Since we're using dynamic libraries, I also don't think there's much of a problem on Android. sqlite3 and sqlcipher can be loaded into the same process there, we're distinguishing symbols by looking them up through the library. iOS is problematic because we're typically linking everything into one bundle, so libraries with duplicate symbol names will cause a clash.
As far as I'm aware, there really is no way to use both sqlite3 and sqlcipher in the same project on iOS. So if you have a dependency on sqlcipher, I'd drop the dependency on sqlite3_flutter_libs
and just have drift use sqlcipher instead (since sqlcipher works without encryption as well).
Original comment mentions a temporary solution, which can be untimatively resolved by https://github.com/dart-lang/sdk/issues/50565
I'd drop the dependency on
sqlite3_flutter_libs
and just have drift use sqlcipher instead
@simolus3 ~Do I have to simply remove sqlite3_flutter_libs
or replace it with sqlcipher_flutter_libs
?~
To use SQLCipher only:
sqlite3_flutter_libs
with sqlcipher_flutter_libs
sqflite
override and sqlcipher_flutter_libs
are using the same SQLCipher
versionSQLCipher 4.5.4
is used by:
fmdb_override
branch (6be83a5)sqlcipher_flutter_libs: 0.5.7
sqlite3.open
as described in this example main.dart in Flutter app:
import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart';
import 'package:sqlite3/open.dart';
void main() {
// No need to override IOS
// because `sqlite3.framework` is already replaced with SQLCipher implementation
open.overrideFor(OperatingSystem.android, openCipherOnAndroid);
WidgetsFlutterBinding.ensureInitialized();
// ...
runApp(...);
}
pubspec.yaml in Flutter app:
dependency_overrides:
sqflite: # fmdb_override
dependencies:
drift:
sqlite3:
sqlcipher_flutter_libs:
pubspec.yaml in Plugin:
dependencies:
drift:
sqlite3:
sqlcipher_flutter_libs:
encrypted_drift: # extras/encryption
Hopefully, the upcoming native-assets feature will fix this by giving us full control over the libraries we want to link.
https://github.com/dart-lang/sdk/issues/50565 would be really a game-changer. Monitoring it now 👀
Problem
On IOS, SQLite (FMDB) and SQLCipher (FMDB/SQLCipher) are in conflict. Avoid linking both of them in the project at the same time. It will lead to unintended unpredictable behavior.
I am having the same issue as described here (
file is not a database
): https://github.com/simolus3/drift/issues/1810Potential fix: https://github.com/simolus3/drift/issues/1810#issuecomment-1119426006
Use Case
Assuming the following use case:
drift
as a DBsqlite3
viaNativeDatabase(...)
)flutter_cache_manager
sqflite
)encrypted_drift
sqflite_sqlcipher
viaEncryptedExecutor(...)
)pubspec.yaml
in Flutter app:pubspec.yaml
in Plugin:Proposition
@simolus3 @davidmartos96 Could you please update the documentation on what is the proper way to set up the described use case?
Especially:
FMDB
andFMDB/SQLCipher
at the same time)?More info on the SQLite vs SQLCipher
Additional links: https://drift.simonbinder.eu/docs/platforms/encryption/#extra-setup-on-android-and-ios https://pub.dev/packages/sqflite_sqlcipher#if-using-sqflite-as-direct-or-transitive-dependency https://pub.dev/packages/sqlcipher_flutter_libs#incompatibilities-with-sqlite3-on-ios-and-macos https://discuss.zetetic.net/t/encrypted-db-in-swift-ios-via-fmdb-can-not-open-in-sql-db-browser/4813/4 https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688 https://discuss.zetetic.net/t/cannot-open-encrypted-database-with-sqlcipher-4/3654/4
More additional links: https://github.com/sqlcipher/sqlcipher https://pub.dev/packages/sqlite3_flutter_libs https://pub.dev/packages/sqlcipher_flutter_libs https://ccgus.github.io/fmdb/html/index.html https://github.com/simolus3/drift/issues/1480 https://discuss.zetetic.net/t/can-sqlite-and-sqlcipher-be-used-simultaneously/3609/2