From 04e1b65a0e70ee63ec93a2f337b0b27bec8c308e Mon Sep 17 00:00:00 2001 From: Oscar Franco Date: Tue, 12 Mar 2024 09:49:07 +0100 Subject: [PATCH] Try to get sources compiled on Android --- android/CMakeLists.txt | 17 ++++++++++++----- android/build.gradle | 16 +++++++++++----- cpp/bindings.cpp | 13 ++++++------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 78bdb427..2489a597 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -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} @@ -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 @@ -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 diff --git a/android/build.gradle b/android/build.gradle index 5d0819b2..90a1a933 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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()) } } diff --git a/cpp/bindings.cpp b/cpp/bindings.cpp index 70c29726..3f7590ff 100644 --- a/cpp/bindings.cpp +++ b/cpp/bindings.cpp @@ -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()) {