Skip to content

Commit

Permalink
Try to get sources compiled on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Mar 12, 2024
1 parent 583c1b4 commit 04e1b65
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
17 changes: 12 additions & 5 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 17)
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)

include_directories(
../cpp
)
include_directories(
../cpp
../cpp/sqlcipher
)

add_definitions(
${SQLITE_FLAGS}
Expand All @@ -21,8 +22,6 @@ add_library(
../cpp/bridge.h
../cpp/bindings.cpp
../cpp/bindings.h
../cpp/sqlite3.h
../cpp/sqlite3.c
../cpp/utils.h
../cpp/utils.cpp
../cpp/ThreadPool.h
Expand All @@ -40,6 +39,14 @@ add_library(
cpp-adapter.cpp
)

if (OP_SQLITE_USE_SQLCIPHER)
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlcipher/sqlite3.h ../cpp/sqlcipher/sqlite3.c)

add_definitions(-DOP_SQLITE_USE_SQLCIPHER)
else()
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlite3.h ../cpp/sqlite3.c)
endif()

set_target_properties(
${PACKAGE_NAME} PROPERTIES
CXX_STANDARD 17
Expand Down
16 changes: 11 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,23 @@ android {
cmake {
if(System.getenv("OP_SQLITE_PERF") == '1') {
println "OP-SQLITE performance mode enabled! 🚀"
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"
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"]
}
if(System.getenv("OP_SQLITE_PERF") == '2') {
println "OP-SQLITE (thread safe) performance mode enabled! 🚀"
cFlags "-DSQLITE_DQS=0", "-DSQLITE_THREADSAFE=1", "-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"
cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_THREADSAFE=1", "-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"]
}

if(System.getenv("OP_SQLITE_USE_SQLCIPHER") == '1') {
println "OP-SQLITE using SQLCipher! 🔒"
cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
}

cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments '-DANDROID_STL=c++_shared',
"-DSQLITE_FLAGS='${SQLITE_FLAGS ? SQLITE_FLAGS : ''}'",
"-DUSE_HERMES=${USE_HERMES}"
arguments "-DOP_SQLITE_USE_SQLCIPHER='${System.getenv("OP_SQLITE_USE_SQLCIPHER")}'",
"-DANDROID_STL=c++_shared",
"-DSQLITE_FLAGS='${SQLITE_FLAGS ? SQLITE_FLAGS : ''}'"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down
13 changes: 6 additions & 7 deletions cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ void install(jsi::Runtime &rt,
"[OP SQLite] using SQLCipher encryption key is required");
}
// TODO(osp) find a way to display the yellow box from c++
// #else
// if (!encryptionKey.empty()) {

// RCTLogWarn(@"Your message")
// throw std::runtime_error("[OP SQLite] SQLCipher is not enabled, "
// "encryption key is not allowed");
// }
#else
if (!encryptionKey.empty()) {
// RCTLogWarn(@"Your message")
throw std::runtime_error("[OP SQLite] SQLCipher is not enabled, "
"encryption key is not allowed");
}
#endif

if (!location.empty()) {
Expand Down

0 comments on commit 04e1b65

Please sign in to comment.