Andrew O Hart
11/15/2021, 12:46 PM./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" \
LDFLAGS="/opt/local/lib/libcrypto.a"
However this gives me an error saying "C compiler cannot create executables"
Also I saw on the forums somebody said to try:
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -I/usr/local/opt/openssl/include/" LDFLAGS="/usr/local/opt/openssl/lib/libcrypto.a"
This looks like it builds but at the end says "error: Library crypto not found. Install openssl!" but I have already installed openssl via homebrew.
Basically I need to get the .a file build and bring it into the ios part of the multiplatform project and then bring in the .h file and create the .def file but its proving trickier than I thought.
I know this isn't exactly related to multiplatform specifically but I thought maybe somebody encountered something similar and could help.
Thanks!russhwolf
11/15/2021, 5:32 PMAndrew O Hart
11/15/2021, 5:50 PMVadim
11/15/2021, 7:05 PMSQLCipher
pod to it, then build it and inspect build logs. Also, there's SQCipher podspec with library-specific compile flags and ./configure
flags they're using https://github.com/CocoaPods/Specs/blob/master/Specs/1/2/7/SQLCipher/4.5.0/SQLCipher.podspec.json
With this information, I could build libSQLCipher.a
like that:
./configure --enable-tempstore=yes --with-crypto-lib=commoncrypto CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLITE_SOUNDEX -DSQLITE_THREADSAFE -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_STAT3 -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_LOAD_EXTENSION -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DHAVE_USLEEP=1 -DSQLITE_MAX_VARIABLE_NUMBER=99999"
make sqlite3.c
`xcrun --sdk iphoneos --find clang` -x c -target arm64-apple-ios8.0 -isysroot `xcrun --sdk iphoneos --show-sdk-path` -fmodules -DSQLITE_HAS_CODEC=1 -fstrict-aliasing -fembed-bitcode-marker -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLITE_SOUNDEX -DSQLITE_THREADSAFE -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_STAT3 -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_LOAD_EXTENSION -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLCIPHER_CRYPTO_CC -DHAVE_USLEEP=1 -DSQLITE_MAX_VARIABLE_NUMBER=99999 -DNDEBUG -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLITE_SOUNDEX -DSQLITE_THREADSAFE -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_STAT3 -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_LOAD_EXTENSION -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_UNLOCK_NOTIFY -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5 -DSQLCIPHER_CRYPTO_CC -DHAVE_USLEEP=1 -DSQLITE_MAX_VARIABLE_NUMBER=99999 -fno-objc-arc -fmodule-name=SQLCipher -Oz -fno-common -c sqlite3.c -o sqlite3.o
`xcrun --sdk iphoneos --find libtool` -static -arch_only arm64 -syslibroot `xcrun --sdk iphoneos --show-sdk-path` -o libSQLCipher.a sqlite3.o
I haven't tested the resulting lib, hope this helps in some way.Andrew O Hart
11/15/2021, 8:30 PMAndrew O Hart
11/15/2021, 8:34 PMVadim
11/16/2021, 9:03 AMAndrew O Hart
11/16/2021, 10:48 AMVadim
11/16/2021, 1:13 PMlinkerOpts(...)
within framework {}
gradle blockAndrew O Hart
11/16/2021, 2:14 PMAndrew O Hart
11/16/2021, 2:15 PMVadim
11/16/2021, 2:49 PMiphoneos
to `watchos`/`iphonesimulator`/etc and arch from arm64
to `armv7`/`x86_64`/etc if you need to build for older devices/watchos/simulator/etc.
What kind of crashes are you experiencing, do you have logs?Andrew O Hart
11/16/2021, 3:10 PMAndrew O Hart
11/16/2021, 3:13 PMAndrew O Hart
11/16/2021, 3:36 PMAndrew O Hart
11/16/2021, 3:36 PMAndrew O Hart
11/16/2021, 3:41 PMAndrew O Hart
11/16/2021, 4:09 PMFunction doesn't have or inherit @Throws annotation and thus exception isn't propagated from Kotlin to Objective-C/Swift as NSError.
It is considered unexpected and unhandled instead. Program will be terminated.
Uncaught Kotlin exception: kotlin.Exception: android/database/sqlite/SQLiteException - unknown error (code 0): Queries can be performed using SQLiteDatabase query or rawQuery methods only.
at 0 testLib 0x00000001011acd98 kfun:kotlin.Throwable#<init>(kotlin.String?){} + 96
at 1 testLib 0x00000001011a4d58 kfun:kotlin.Exception#<init>(kotlin.String?){} + 92
at 2 testLib 0x00000001012aff80 ThrowSql_SQLiteException + 384
at 3 testLib 0x000000010179f0f8 _ZN7android23throw_sqlite3_exceptionEiPKcS1_ + 960
at 4 testLib 0x000000010179f46c _ZN7android31throw_sqlite3_exception_errcodeEiPKc + 0
at 5 testLib 0x000000010179fec8 SQLiter_SQLiteStatement_nativeExecute + 72
at 6 testLib 0x00000001012b6788 kfun:co.touchlab.sqliter.NativeStatement#execute(){} + 208
at 7 testLib 0x00000001012a6260 kfun:co.touchlab.sqliter.setCipherKey$lambda-0#internal + 116
at 8 testLib 0x00000001012a6634 kfun:co.touchlab.sqliter.$setCipherKey$lambda-0$FUNCTION_REFERENCE$313.invoke#internal + 76
at 9 testLib 0x00000001012a66b4 kfun:co.touchlab.sqliter.$setCipherKey$lambda-0$FUNCTION_REFERENCE$313.$<bridge-UNNN>invoke(-1:0){}#internal + 96
at 10 testLib 0x00000001012a5764 kfun:co.touchlab.sqliter#withStatement@co.touchlab.sqliter.DatabaseConnection(kotlin.String;kotlin.Function1<co.touchlab.sqliter.Statement,0:0>){0§<kotlin.Any?>}0:0 + 412
at 11 testLib 0x00000001012a4f30 kfun:co.touchlab.sqliter#setCipherKey@co.touchlab.sqliter.DatabaseConnection(kotlin.String){} + 428
at 12 testLib 0x00000001012b549c kfun:co.touchlab.sqliter.NativeDatabaseManager.createConnection#internal + 1936
at 13 testLib 0x00000001012b4998 kfun:co.touchlab.sqliter.NativeDatabaseManager#createMultiThreadedConnection(){}co.touchlab.sqliter.DatabaseConnection + 160
at 14 testLib 0x00000001012b8b50 kfun:com.squareup.sqldelight.drivers.native.NativeSqliteDriver.<init>$lambda-0#internal + 232
at 15 testLib 0x00000001012b9248 kfun:com.squareup.sqldelight.drivers.native.NativeSqliteDriver.$<init>$lambda-0$FUNCTION_REFERENCE$295.invoke#internal + 144
at 16 testLib 0x00000001012bd7cc kfun:com.squareup.sqldelight.drivers.native.SinglePool#<init>(kotlin.Function0<1:0>){} + 592
at 17 testLib 0x00000001012b7ccc kfun:com.squareup.sqldelight.drivers.native.NativeSqliteDriver#<init>(co.touchlab.sqliter.DatabaseManager){} + 444
at 18 testLib 0x00000001012b7f08 kfun:com.squareup.sqldelight.drivers.native.NativeSqliteDriver#<init>(co.touchlab.sqliter.DatabaseConfiguration){} + 176
at 19 testLib 0x000000010168bc10 kfun:databaseRetriever.DatabaseRetriever#getDatabase(){}com.test.testLib.testLibDatabase + 484
at 20 testLib 0x0000000101597240 kfun:dao.factory.RealDaoFactory#<init>(databaseRetriever.IDatabaseRetriever){} + 400
at 21 testLib 0x000000010169cfa4 kfun:gateway.testLib#getGateway(synchronization.configuration.GatewayConfiguration;genericdevices.Delgate;genericdevices.PrinterDelegate;genericdevices.BarcodeScannerDelegate){}gateway.Gateway + 912
at 22 testLib 0x0000000101734764 objc2kotlin.2474 + 296
at 23 testLibDemo 0x0000000100d1a9e4 $s15testLibDemo35DeviceIntegrationTestViewControllerC11viewDidLoadyyFTo + 32
at 24 UIKitCore 0x00000001ad03ce50 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4623952
at 25 UIKitCore 0x00000001ad041408 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 4641800
at 26 UIKitCore 0x00000001acf88a94 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3885716
at 27 UIKitCore 0x00000001acf88d9c CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3886492
at 28 UIKitCore 0x00000001acf89c60 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3890272
at 29 UIKitCore 0x00000001acf8afe0 CC6E5AC7-8248-35F6-8B42-2E25C93DCF0A + 3895264
Andrew O Hart
11/16/2021, 4:09 PMAndrew O Hart
11/16/2021, 4:09 PMprivate fun getConfiguration(schema: SqlDriver.Schema, name: String, inMemory: Boolean): DatabaseConfiguration {
return DatabaseConfiguration(
name = name,
version = schema.version,
create = { connection ->
wrapConnection(connection) { schema.create(it) }
},
upgrade = { connection, oldVersion, newVersion ->
wrapConnection(connection) { schema.migrate(it, oldVersion, newVersion) }
},
inMemory = inMemory,
key = "testPassphrase"
)
}
Andrew O Hart
11/16/2021, 4:10 PMVadim
11/16/2021, 4:18 PMAndrew O Hart
11/16/2021, 4:21 PMAndrew O Hart
11/16/2021, 4:21 PMVadim
11/16/2021, 4:23 PMAndrew O Hart
11/24/2021, 10:31 AM/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
But from the commands we use it looks like its included.
Any ideas on potential fixes?Vadim
11/24/2021, 1:31 PMAndrew O Hart
11/24/2021, 1:40 PM/* BEGIN SQLCIPHER */
#ifdef SQLITE_HAS_CODEC
// sqlite3_key(), sqlite3_key_v2(), sqlite3_rekey(), sqlite3_rekey_v2(), sqlite3_activate_see() methods are defined here
#endif
/* END SQLCIPHER */
Vadim
11/24/2021, 3:08 PMAndrew O Hart
11/24/2021, 3:13 PMAndrew O Hart
11/24/2021, 3:15 PMVadim
11/24/2021, 10:04 PMAndrew O Hart
11/25/2021, 10:19 AMAndrew O Hart
11/25/2021, 12:28 PMcompilerOpts("-DSQLITE_HAS_CODEC=1")
to the .def file seems to of fixed it!
Thanks for the help along the way. I will have to write an article on this after I'm finished incase anybody gets stuck with itVadim
11/25/2021, 3:17 PM=1
but I'm not sure
all xcrun flags are “standard” for clang cross compiling for ios. Xcode generates them according to project config. What I've done was created a new Xcode app project, added sqlcipher cocoapod to it and then compiled. After that I had a log with all the build commands so I just extracted these flags from it because I don't remember all of them :) there were couple of other flags like commands to silence some compiler warnings, I just omitted them.Andrew O Hart
11/26/2021, 12:00 AMvar rc: Int32
var db: OpaquePointer? = nil
var stmt: OpaquePointer? = nil
let password: String = "correct horse battery staple"
rc = sqlite3_open(":memory:", &db)
if (rc != SQLITE_OK) {
let errmsg = String(cString: sqlite3_errmsg(db))
NSLog("Error opening database: \(errmsg)")
return
}
rc = sqlite3_key(db, password, Int32(password.utf8CString.count))
Which doesn't really translate to Kotlin too well. I have tried this:
var rc: Int
val db: CValuesRef<CPointerVar<cnames.structs.sqlite3>>? = null
val db2: CValuesRef<cnames.structs.sqlite3>? = null
rc = sqlite3_open(databasePath.encodeToByteArray(), db)
val isOk = rc == SQLITE_OK
NSLog(isOk.toString())
rc = sqlite3_key(db2, null, 0)
val isOk2 = rc == SQLITE_OK
NSLog(isOk2.toString())
I have 2 dbs here because the first db only works in the sqlite3_open and the 2nd one works in the sqlite3_key call. It doesn't make sense to me because the example they show just has 1 db object. None of this works anyway as it crashes on ios when I try run it. Something strange going on for sure, I had to add null to the sqlite3_key because it wouldn't accept a string even though the example has one.
Sorry for all the questions but thought you might have an idea 😄Vadim
11/26/2021, 12:39 PMAndrew O Hart
11/26/2021, 12:53 PMAndrew O Hart
11/26/2021, 12:53 PMAndrew O Hart
11/26/2021, 12:55 PMAndrew O Hart
11/26/2021, 12:56 PMVadim
11/26/2021, 3:44 PMAndrew O Hart
11/26/2021, 4:35 PM