Damiano Giusti
12/09/2024, 4:28 PM-lsqlite3
flag neither in the .def
file nor in the build.gradle file. Unfortunately, when I run the tests on the iOS simulator I get a bunch of errors that likely indicate that I didn’t link sqlite3
e: /Applications/Xcode-15.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
The /Applications/Xcode-15.4.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
Undefined symbols for architecture arm64:
"_sqlite3_bind_blob", referenced from:
_co_touchlab_sqliter_sqlite3_sqlite3_bind_blob_wrapper69 in test.kexe.o
"_sqlite3_bind_double", referenced from:
_co_touchlab_sqliter_sqlite3_sqlite3_bind_double_wrapper71 in test.kexe.o
....
On the other hand, if I link sqlite3 in the def file I’m able to run the test but I get the following error
error rawExecSql: ATTACH DATABASE '/Users/damianogiusti/Library/Developer/CoreSimulator/Devices/3511AD2C-AAC6-4392-B854-166C3737D57A/data/Library/Application Support/databases/encryptedDatabase.db' AS encryptedDb KEY 'mostSecurePasswordEver', file is not a database | error code SQLITE_NOTADB
the database file exists on disk but if I open it with an editor before running the ATTACH command looks like it is not encrypted.
Also, running PRAGMA cipher_version
returns nothing. I think that sqlcipher is not recognized at runtime because I linked sqlite3, thus the system embedded sqlite.
I had a look also at this github issue but it didn’t help: https://github.com/sqldelight/sqldelight/issues/1442
Anyone can help? thank you! 🙏kpgalligan
12/09/2024, 6:13 PMUnfortunately, when I run the tests on the iOS simulator I get a bunch of errors that likely indicate that I didn’t link sqlite3Those errors are definitely liker errors saying it can't find a sqlite implementation (system or sqlcipher).
On the other hand, if I link sqlite3 in the def file I’m able to run the test but I get the following error
the database file exists on disk but if I open it with an editor before running the ATTACH command looks like it is not encrypted.sqlcipher on iOS is tricky. There are several things you need to do, IIRC. Obviously you need the sqlcipher version of sqlite. Then, avoid linking the system build. There is also some flag in Xcode that needs to be set (not the linker flag). The flag might only be needed if you build sqlcipher in Xcode, vs however you're including sqlcipher.
Unfortunately, when I run the tests on the iOS simulator I get a bunch of errors that likely indicate that I didn’t link sqlite3Are you running xctests in Xcode, or are these the Kotlin tests that get run from the Kotlin build? Kotlin tests do run on a simulator, but you don't really "see" it happen, so when somebody mentions simulator sometimes they mean they're running xctests from Xcode and using the Kotlin, which is a set of potentially different issues.
kpgalligan
12/09/2024, 6:16 PMkpgalligan
12/09/2024, 6:17 PMkpgalligan
12/09/2024, 6:17 PMDamiano Giusti
12/09/2024, 6:20 PMAre you running xctests in Xcode, or are these the Kotlin tests that get run from the Kotlin build?I’m running kotlin tests under the commonTest directory targeting iosSimulatorArm64… So basically you’re suggesting to use plain sql for my kmp module, but link sqlcipher directly on the host Xcode project, right? My goal was to embed sqlcipher in the umbrella kmp xcframework, that is the one we import on the xcode project. I thought that if I linked sqlcipher inside it then I could have used directly the xcframework without additional configurations on xcode side
kpgalligan
12/09/2024, 6:20 PMkpgalligan
12/09/2024, 6:31 PMSo basically you’re suggesting to use plain sql for my kmp module, but link sqlcipher directly on the host Xcode project, right?I'd replacing "suggesting" with "saying the thing you did once". It's an option, but it depends on what you're doing.
My goal was to embed sqlcipher in the umbrella kmp xcframework, that is the one we import on the xcode project. I thought that if I linked sqlcipher inside it then I could have used directly the xcframework without additional configurations on xcode sidecinterop doesn't embed anything itself. It just generates kotlin definitions for native calls. You could need something else that compiles the sqlcipher version of sqlite.c into platform-compatible binary library code, then tell the Kotlin compiler that you want that binary embedded. Conceptually simple, in practice, complicated. An example of code that does this is zipline. It builds some c code, and adds it to the library publication. It's not exactly the same thing, as the output is a klib and not a framework.: https://github.com/cashapp/zipline/blob/trunk/zipline/build.gradle.kts I don't off-hand know of an easy way to just tell the Kotlin compiler to add some c code and compile it. There might be a much easier approach that I'm forgetting, but I don't think so. KMP and linking native dependencies is an ongoing issue for a few of our libraries. Anyway, to replicate what zipline is doing, you could have a KMP module who's only purpose is to compile the sqlcipher c code, then include that in your project to build the umbrella. cinterop actually wouldn't accomplish anything here. You need to have the c bindings available to the linker.
kpgalligan
12/09/2024, 6:32 PMDamiano Giusti
12/13/2024, 5:10 PMMJegorovas
01/24/2025, 1:40 PM