diff --git a/src/android/com_reacttests_RealmReactAndroid.cpp b/src/android/com_reacttests_RealmReactAndroid.cpp index 3fb2da0b..7e1f83ad 100644 --- a/src/android/com_reacttests_RealmReactAndroid.cpp +++ b/src/android/com_reacttests_RealmReactAndroid.cpp @@ -8,6 +8,7 @@ #include "com_reacttests_RealmReactAndroid.h" #include "JSCExecutor.h" #include "js_init.h" +#include "platform.hpp" #include /* @@ -27,7 +28,8 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon // Getting the internal storage path for the application const char* strFileDir = env->GetStringUTFChars(fileDir , NULL); std::string absoluteAppPath(strFileDir); - env->ReleaseStringUTFChars(fileDir , strFileDir); + env->ReleaseStringUTFChars(fileDir , strFileDir); + realm::set_default_realm_file_directory(absoluteAppPath); // load the symbol typedef std::unordered_map (*get_jsc_context_t)(); @@ -40,7 +42,7 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon msg << "Got the globalContext map, size=" << s_globalContextRefToJSCExecutor.size(); for (auto pair : s_globalContextRefToJSCExecutor) { - RJSInitializeInContextUsingPath(pair.first, absoluteAppPath); + RJSInitializeInContext(pair.first); } return env->NewStringUTF(msg.str().c_str()); diff --git a/src/android/platform.cpp b/src/android/platform.cpp index a2ad3b3c..f87e9c53 100644 --- a/src/android/platform.cpp +++ b/src/android/platform.cpp @@ -8,10 +8,14 @@ namespace realm { + static std::string s_default_realm_directory; + void set_default_realm_file_directory(std::string dir) { + s_default_realm_directory = dir; + } + std::string default_realm_file_directory() { - // appFilesDir is defined in js_init.cpp - return appFilesDir; + return s_default_realm_directory; } void ensure_directory_exists_for_file(const std::string &fileName) diff --git a/src/js_init.cpp b/src/js_init.cpp index 7659f77d..09572007 100644 --- a/src/js_init.cpp +++ b/src/js_init.cpp @@ -78,16 +78,6 @@ void RJSInitializeInContext(JSContextRef ctx) { assert(!exception); } -// The default (internal) storage for each application is unique -// the only way to get this path is using the android.content.Context via the JNI -// we set this path when we initialise the Realm by calling RJSConstructorCreate, as it's the -// only contact between the JNI layer and the Realm JS API. -std::string appFilesDir; -void RJSInitializeInContextUsingPath(JSContextRef ctx, std::string path) { - RJSInitializeInContext(ctx); - appFilesDir = path; -} - void RJSClearTestState() { realm::Realm::s_global_cache.clear(); realm::remove_realm_files_from_directory(realm::default_realm_file_directory()); diff --git a/src/js_init.h b/src/js_init.h index 95b6757f..be9f38aa 100644 --- a/src/js_init.h +++ b/src/js_init.h @@ -13,11 +13,8 @@ extern "C" { JSObjectRef RJSConstructorCreate(JSContextRef ctx); void RJSInitializeInContext(JSContextRef ctx); -void RJSInitializeInContextUsingPath(JSContextRef ctx, std::string path); void RJSClearTestState(void); -extern std::string appFilesDir; - #ifdef __cplusplus } #endif diff --git a/src/platform.hpp b/src/platform.hpp index 0b1c5024..95aadbab 100644 --- a/src/platform.hpp +++ b/src/platform.hpp @@ -15,7 +15,10 @@ namespace realm { // separately for eadh platform // -// return the directory in which realm files can/should be written to + // set the directory where realm files should be stored + void set_default_realm_file_directory(std::string dir); + + // return the directory in which realm files can/should be written to std::string default_realm_file_directory(); // create the directories for the given filename diff --git a/tests/react-test-app/run-android.sh b/tests/react-test-app/run-android.sh new file mode 100644 index 00000000..bdd9fe43 --- /dev/null +++ b/tests/react-test-app/run-android.sh @@ -0,0 +1,6 @@ +#!/bin/bash +cp ../../react-native/android/app/build/outputs/aar/app-debug.aar android/app/lib/ +rm -rf node_modules/realm node_modules/realm-tests +npm install realm realm-tests +cp ../../src/object-store/parser/queryTests.json node_modules/realm-tests/ +react-native run-android