diff --git a/examples/encryption/android/app/build.gradle b/examples/encryption/android/app/build.gradle index fea7a8c7..6da8d9a7 100644 --- a/examples/encryption/android/app/build.gradle +++ b/examples/encryption/android/app/build.gradle @@ -47,7 +47,7 @@ android { applicationId "com.example.drift_encryption_sample" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. - minSdkVersion flutter.minSdkVersion + minSdkVersion 21 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/examples/encryption/android/build.gradle b/examples/encryption/android/build.gradle index 83ae2200..3cdaac95 100644 --- a/examples/encryption/android/build.gradle +++ b/examples/encryption/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/examples/encryption/lib/database.dart b/examples/encryption/lib/database.dart index d2c90e85..cd5b4dee 100644 --- a/examples/encryption/lib/database.dart +++ b/examples/encryption/lib/database.dart @@ -1,9 +1,12 @@ +import 'dart:ffi'; import 'dart:io'; import 'package:drift/drift.dart'; import 'package:drift/native.dart'; import 'package:path/path.dart' as p; import 'package:path_provider/path_provider.dart'; +import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart'; +import 'package:sqlite3/open.dart'; part 'database.g.dart'; @@ -39,6 +42,14 @@ QueryExecutor _openDatabase() { return NativeDatabase.createInBackground( File(p.join(path.path, 'app.db.enc')), + isolateSetup: () async { + open + ..overrideFor(OperatingSystem.android, openCipherOnAndroid) + ..overrideFor(OperatingSystem.linux, + () => DynamicLibrary.open('libsqlcipher.so')) + ..overrideFor(OperatingSystem.windows, + () => DynamicLibrary.open('sqlcipher.dll')); + }, setup: (db) { // Check that we're actually running with SQLCipher by quering the // cipher_version pragma. diff --git a/examples/encryption/lib/main.dart b/examples/encryption/lib/main.dart index 6445b5b1..bc489fbf 100644 --- a/examples/encryption/lib/main.dart +++ b/examples/encryption/lib/main.dart @@ -1,20 +1,9 @@ -import 'dart:ffi'; - import 'package:drift/drift.dart'; import 'package:flutter/material.dart'; -import 'package:sqlite3/open.dart'; -import 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart'; import 'database.dart'; void main() { - open - ..overrideFor(OperatingSystem.android, openCipherOnAndroid) - ..overrideFor( - OperatingSystem.linux, () => DynamicLibrary.open('libsqlcipher.so')) - ..overrideFor( - OperatingSystem.windows, () => DynamicLibrary.open('sqlcipher.dll')); - runApp(const MyApp()); }