From 6156e912930c12d89f161823df969c8b81e3bc04 Mon Sep 17 00:00:00 2001 From: Sebastian Single Date: Mon, 16 Oct 2023 10:41:40 +0200 Subject: [PATCH 1/2] use cacheDir for setting TMPDIR env to solve android 12 issue --- android/cpp-adapter.cpp | 6 ++++-- .../java/com/reactnativequicksqlite/QuickSQLiteBridge.java | 6 ++++-- cpp/bindings.cpp | 6 +++++- cpp/bindings.h | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/android/cpp-adapter.cpp b/android/cpp-adapter.cpp index 9859ad7..449a833 100644 --- a/android/cpp-adapter.cpp +++ b/android/cpp-adapter.cpp @@ -24,12 +24,14 @@ struct QuickSQLiteBridge : jni::JavaClass { static void installNativeJsi( jni::alias_ref thiz, jlong jsiRuntimePtr, jni::alias_ref jsCallInvokerHolder, - jni::alias_ref docPath) { + jni::alias_ref docPath, + jni::alias_ref cachePath) { auto jsiRuntime = reinterpret_cast(jsiRuntimePtr); auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); std::string docPathString = docPath->toStdString(); + std::string cachePathString = cachePath->toStdString(); - osp::install(*jsiRuntime, jsCallInvoker, docPathString.c_str()); + osp::install(*jsiRuntime, jsCallInvoker, docPathString.c_str(), cachePathString.c_str()); } static void clearStateNativeJsi(jni::alias_ref thiz) { diff --git a/android/src/main/java/com/reactnativequicksqlite/QuickSQLiteBridge.java b/android/src/main/java/com/reactnativequicksqlite/QuickSQLiteBridge.java index 4c2a2bc..cac4ea0 100644 --- a/android/src/main/java/com/reactnativequicksqlite/QuickSQLiteBridge.java +++ b/android/src/main/java/com/reactnativequicksqlite/QuickSQLiteBridge.java @@ -7,7 +7,7 @@ import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; public class QuickSQLiteBridge { - private native void installNativeJsi(long jsContextNativePointer, CallInvokerHolderImpl jsCallInvokerHolder, String docPath); + private native void installNativeJsi(long jsContextNativePointer, CallInvokerHolderImpl jsCallInvokerHolder, String docPath, String cachePath); private native void clearStateNativeJsi(); public static final QuickSQLiteBridge instance = new QuickSQLiteBridge(); @@ -15,11 +15,13 @@ public void install(ReactContext context) { long jsContextPointer = context.getJavaScriptContextHolder().get(); CallInvokerHolderImpl jsCallInvokerHolder = (CallInvokerHolderImpl)context.getCatalystInstance().getJSCallInvokerHolder(); final String path = context.getFilesDir().getAbsolutePath(); + final String cachePath = context.getCacheDir().getAbsolutePath(); installNativeJsi( jsContextPointer, jsCallInvokerHolder, - path + path, + cachePath ); } diff --git a/cpp/bindings.cpp b/cpp/bindings.cpp index 34adcd0..1ca234b 100644 --- a/cpp/bindings.cpp +++ b/cpp/bindings.cpp @@ -9,6 +9,7 @@ #include #include "macros.h" #include +#include using namespace std; using namespace facebook; @@ -21,8 +22,11 @@ void clearState() { sqliteCloseAll(); } -void install(jsi::Runtime &rt, std::shared_ptr jsCallInvoker, const char *docPath) +void install(jsi::Runtime &rt, std::shared_ptr jsCallInvoker, const char *docPath, const char *cachePath) { + // android 12 fix + setenv("TMPDIR", cachePath, 1); + docPathStr = std::string(docPath); auto pool = std::make_shared(); invoker = jsCallInvoker; diff --git a/cpp/bindings.h b/cpp/bindings.h index 2cc2304..c4ce24b 100644 --- a/cpp/bindings.h +++ b/cpp/bindings.h @@ -5,7 +5,7 @@ using namespace facebook; namespace osp { -void install(jsi::Runtime &rt, std::shared_ptr jsCallInvoker, const char *docPath); +void install(jsi::Runtime &rt, std::shared_ptr jsCallInvoker, const char *docPath, const char *cachePath); void clearState(); } From 7c2d32b868042584e017f7ba168aa49eac4d6f12 Mon Sep 17 00:00:00 2001 From: Sebastian Single Date: Mon, 16 Oct 2023 12:00:38 +0200 Subject: [PATCH 2/2] use NSTemporaryDirectory for ios TMPDIR --- ios/QuickSQLite.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/QuickSQLite.mm b/ios/QuickSQLite.mm index 519f31a..abbec98 100644 --- a/ios/QuickSQLite.mm +++ b/ios/QuickSQLite.mm @@ -52,8 +52,9 @@ @implementation QuickSQLite NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true); documentPath = [paths objectAtIndex:0]; } + NSString *cachePath = NSTemporaryDirectory(); - osp::install(runtime, callInvoker, [documentPath UTF8String]); + osp::install(runtime, callInvoker, [documentPath UTF8String], [cachePath UTF8String]); return @true; }