Skip to content

Commit

Permalink
Fix Android SQLCipher compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Apr 22, 2024
1 parent e951456 commit ed9c882
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
38 changes: 24 additions & 14 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ add_library(
cpp-adapter.cpp
)

if (OP_SQLITE_USE_SQLCIPHER)
if (USE_SQLCIPHER)
message("Using SQLCipher!")
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlcipher/sqlite3.h ../cpp/sqlcipher/sqlite3.c)

add_definitions(
Expand All @@ -53,7 +54,7 @@ else()
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlite3.h ../cpp/sqlite3.c)
endif()

if (OP_SQLITE_USE_CRSQLITE)
if (USE_CRSQLITE)
add_definitions(
-DOP_SQLITE_USE_CRSQLITE=1
)
Expand All @@ -70,16 +71,25 @@ find_package(ReactAndroid REQUIRED CONFIG)
find_package(fbjni REQUIRED CONFIG)
find_library(LOG_LIB log)

target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::turbomodulejsijni
ReactAndroid::react_nativemodule_core
android
)

if (OP_SQLITE_USE_SQLCIPHER)
target_link_libraries(${PACKAGE_NAME} PRIVATE openssl::crypto)
if (USE_SQLCIPHER)
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::turbomodulejsijni
ReactAndroid::react_nativemodule_core
android
openssl::crypto
)
else()
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::turbomodulejsijni
ReactAndroid::react_nativemodule_core
android
)
endif()
18 changes: 13 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,21 @@ android {
}

defaultConfig {
minSdkVersion 21
minSdkVersion 23
targetSdkVersion safeExtGet('targetSdkVersion', 34)
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
if(useSQLCipher) {
cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
}
if(useCRSQLite) {
cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
}
if(performanceMode == '1') {
cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_THREADSAFE=0", "-DSQLITE_DEFAULT_MEMSTATUS=0", "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1", "-DSQLITE_MAX_EXPR_DEPTH=0", "-DSQLITE_OMIT_DEPRECATED=1", "-DSQLITE_OMIT_PROGRESS_CALLBACK=1", "-DSQLITE_OMIT_SHARED_CACHE=1", "-DSQLITE_USE_ALLOCA=1"]
}
Expand All @@ -117,9 +125,9 @@ android {
cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments "-DANDROID_STL=c++_shared",
"-DSQLITE_FLAGS='$sqliteFlags'"
"-DOP_SQLITE_USE_SQLCIPHER='${useSQLCipher? 1 : 0}'"
"-DOP_SQLITE_USE_CRSQLITE='${useCRSQLite? 1 : 0}'"
"-DSQLITE_FLAGS='$sqliteFlags'",
"-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
"-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down Expand Up @@ -170,7 +178,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
dependencies {
implementation 'com.facebook.react:react-native'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
if (System.getenv("OP_SQLITE_USE_SQLCIPHER") == '1') {
if (useSQLCipher) {
implementation('com.android.ndk.thirdparty:openssl:1.1.1q-beta-1')
}
}
Expand Down
6 changes: 5 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ PODS:
- hermes-engine/Pre-built (= 0.74.0-rc.6)
- hermes-engine/Pre-built (0.74.0-rc.6)
- op-sqlite (5.0.2):
- OpenSSL-Universal
- React
- React-callinvoker
- React-Core
- OpenSSL-Universal (3.1.5001)
- RCT-Folly (2024.01.01.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -1234,6 +1236,7 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- OpenSSL-Universal
- SocketRocket

EXTERNAL SOURCES:
Expand Down Expand Up @@ -1358,7 +1361,8 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: 1a846a8f620a08c60f5f89aa65b8664f769f742f
op-sqlite: d66e798e3019d7e50f80f305cb2fdb8ab18abcb4
op-sqlite: 41caa3456901ee4b793fb6ca84ba1dc147ddf199
OpenSSL-Universal: 29a9c9d4baf23f5fcd1294b657e4cc275e605bc3
RCT-Folly: 045d6ecaa59d826c5736dfba0b2f4083ff8d79df
RCTDeprecation: 82b53c4f460b7a5b27c6be8310a71bc84df583f5
RCTRequired: d1a99a9f78fcc4acca99ab397822f4e58601b134
Expand Down
4 changes: 4 additions & 0 deletions example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export function dbSetupTests() {
name: 'versionTest.sqlite',
encryptionKey: 'test',
});

const cipherVersion = db.execute('PRAGMA cipher_version;');
console.warn(cipherVersion);
const res = db.execute('select sqlite_version();');
// console.warn(res.rows?._array[0]['sqlite_version()']);
expect(res.rows?._array[0]['sqlite_version()']).to.equal(expectedVersion);
db.close();
});
Expand Down

0 comments on commit ed9c882

Please sign in to comment.