fix crash in using s_default_realm_directory
This commit is contained in:
parent
529ea5cf70
commit
b246f017e9
|
@ -118,6 +118,7 @@ task buildReactNdkLib(dependsOn: [prepareJSC], type: Exec) {
|
||||||
'-C', file('src/main/jni').absolutePath,
|
'-C', file('src/main/jni').absolutePath,
|
||||||
'-B',
|
'-B',
|
||||||
'NDK_LOG=1',
|
'NDK_LOG=1',
|
||||||
|
'NDK_DEBUG=1',
|
||||||
'--jobs', Runtime.runtime.availableProcessors(),
|
'--jobs', Runtime.runtime.availableProcessors(),
|
||||||
'V=1'
|
'V=1'
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,6 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
Exception exception = new Exception();
|
|
||||||
exception.fillInStackTrace();
|
|
||||||
exception.printStackTrace();
|
|
||||||
|
|
||||||
Log.w("RealmReactAndroid", injectRealmJsContext(filesDirPath));
|
Log.w("RealmReactAndroid", injectRealmJsContext(filesDirPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,21 +38,6 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
|
||||||
return "RealmReactAndroid";
|
return "RealmReactAndroid";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Object> getConstants() {
|
|
||||||
final Map<String, Object> constants = new HashMap<>();
|
|
||||||
constants.put(DURATION_SHORT_KEY, Toast.LENGTH_SHORT);
|
|
||||||
constants.put(DURATION_LONG_KEY, Toast.LENGTH_LONG);
|
|
||||||
|
|
||||||
Exception exception = new Exception();
|
|
||||||
exception.fillInStackTrace();
|
|
||||||
exception.printStackTrace();
|
|
||||||
|
|
||||||
Log.w("RealmReactAndroid", injectRealmJsContext(filesDirPath));
|
|
||||||
|
|
||||||
return constants;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void resultOfJsContextInjection(Callback successCallback) {
|
public void resultOfJsContextInjection(Callback successCallback) {
|
||||||
// Inject our JS Context
|
// Inject our JS Context
|
||||||
|
|
|
@ -47,7 +47,7 @@ LOCAL_C_INCLUDES += core/include
|
||||||
CXX11_FLAGS := -std=c++14
|
CXX11_FLAGS := -std=c++14
|
||||||
LOCAL_CFLAGS += -fexceptions $(CXX11_FLAGS) -frtti
|
LOCAL_CFLAGS += -fexceptions $(CXX11_FLAGS) -frtti
|
||||||
LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS)
|
LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS)
|
||||||
|
LOCAL_LDLIBS := -llog
|
||||||
|
|
||||||
LOCAL_STATIC_LIBRARIES := realm-android-$(TARGET_ARCH_ABI)
|
LOCAL_STATIC_LIBRARIES := realm-android-$(TARGET_ARCH_ABI)
|
||||||
LOCAL_SHARED_LIBRARIES := libjsc
|
LOCAL_SHARED_LIBRARIES := libjsc
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "js_init.h"
|
#include "js_init.h"
|
||||||
#include "platform.hpp"
|
#include "platform.hpp"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <android/log.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: com_reacttests_RealmReactAndroid
|
* Class: com_reacttests_RealmReactAndroid
|
||||||
|
@ -19,7 +20,7 @@
|
||||||
JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
|
JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
|
||||||
(JNIEnv *env, jclass, jstring fileDir)
|
(JNIEnv *env, jclass, jstring fileDir)
|
||||||
{
|
{
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Java_com_reacttests_RealmReactAndroid_injectRealmJsContext");
|
||||||
void* handle = dlopen ("libreactnativejni.so", RTLD_LAZY);
|
void* handle = dlopen ("libreactnativejni.so", RTLD_LAZY);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
return env->NewStringUTF("Cannot open library");
|
return env->NewStringUTF("Cannot open library");
|
||||||
|
@ -29,7 +30,9 @@ JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsCon
|
||||||
const char* strFileDir = env->GetStringUTFChars(fileDir , NULL);
|
const char* strFileDir = env->GetStringUTFChars(fileDir , NULL);
|
||||||
std::string absoluteAppPath(strFileDir);
|
std::string absoluteAppPath(strFileDir);
|
||||||
env->ReleaseStringUTFChars(fileDir , strFileDir);
|
env->ReleaseStringUTFChars(fileDir , strFileDir);
|
||||||
|
|
||||||
realm::set_default_realm_file_directory(absoluteAppPath);
|
realm::set_default_realm_file_directory(absoluteAppPath);
|
||||||
|
__android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Absolute path %s", realm::default_realm_file_directory().c_str());
|
||||||
|
|
||||||
// load the symbol
|
// load the symbol
|
||||||
typedef std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> (*get_jsc_context_t)();
|
typedef std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> (*get_jsc_context_t)();
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
#include "../js_init.h"
|
#include "../js_init.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
std::string s_default_realm_directory;
|
||||||
|
|
||||||
namespace realm {
|
namespace realm {
|
||||||
|
|
||||||
static std::string s_default_realm_directory;
|
void set_default_realm_file_directory(std::string dir) {
|
||||||
void set_default_realm_file_directory(std::string dir) {
|
s_default_realm_directory = dir;
|
||||||
s_default_realm_directory = dir;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::string default_realm_file_directory()
|
std::string default_realm_file_directory()
|
||||||
{
|
{
|
||||||
|
|
|
@ -105,8 +105,10 @@ std::map<std::string, JSValueRef> &RJSPrototypes(Realm *realm) {
|
||||||
return static_cast<RJSRealmDelegate *>(realm->m_binding_context.get())->m_prototypes;
|
return static_cast<RJSRealmDelegate *>(realm->m_binding_context.get())->m_prototypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string s_defaultPath = realm::default_realm_file_directory() + "/default.realm";
|
// static std::string s_defaultPath = realm::default_realm_file_directory() + "/default.realm";
|
||||||
|
static std::string s_defaultPath = "";
|
||||||
std::string RJSDefaultPath() {
|
std::string RJSDefaultPath() {
|
||||||
|
s_defaultPath = realm::default_realm_file_directory() + "/default.realm";
|
||||||
return s_defaultPath;
|
return s_defaultPath;
|
||||||
}
|
}
|
||||||
void RJSSetDefaultPath(std::string path) {
|
void RJSSetDefaultPath(std::string path) {
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace realm {
|
extern std::string s_default_realm_directory;
|
||||||
|
|
||||||
|
namespace realm {
|
||||||
//
|
//
|
||||||
// These methods are used internally and must be implemented
|
// These methods are used internally and must be implemented
|
||||||
// separately for eadh platform
|
// separately for eadh platform
|
||||||
|
|
Loading…
Reference in New Issue