fix crash in using s_default_realm_directory

This commit is contained in:
Nabil Hachicha 2016-01-12 03:01:06 +00:00
parent 529ea5cf70
commit b246f017e9
7 changed files with 17 additions and 28 deletions

View File

@ -118,6 +118,7 @@ task buildReactNdkLib(dependsOn: [prepareJSC], type: Exec) {
'-C', file('src/main/jni').absolutePath,
'-B',
'NDK_LOG=1',
'NDK_DEBUG=1',
'--jobs', Runtime.runtime.availableProcessors(),
'V=1'
}

View File

@ -30,10 +30,6 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
@Override
public void initialize() {
Exception exception = new Exception();
exception.fillInStackTrace();
exception.printStackTrace();
Log.w("RealmReactAndroid", injectRealmJsContext(filesDirPath));
}
@ -42,21 +38,6 @@ public class RealmReactAndroid extends ReactContextBaseJavaModule {
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
public void resultOfJsContextInjection(Callback successCallback) {
// Inject our JS Context

View File

@ -47,7 +47,7 @@ LOCAL_C_INCLUDES += core/include
CXX11_FLAGS := -std=c++14
LOCAL_CFLAGS += -fexceptions $(CXX11_FLAGS) -frtti
LOCAL_EXPORT_CPPFLAGS := $(CXX11_FLAGS)
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := realm-android-$(TARGET_ARCH_ABI)
LOCAL_SHARED_LIBRARIES := libjsc

View File

@ -10,6 +10,7 @@
#include "js_init.h"
#include "platform.hpp"
#include <unordered_map>
#include <android/log.h>
/*
* Class: com_reacttests_RealmReactAndroid
@ -19,7 +20,7 @@
JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
(JNIEnv *env, jclass, jstring fileDir)
{
__android_log_print(ANDROID_LOG_ERROR, "JSRealm", "Java_com_reacttests_RealmReactAndroid_injectRealmJsContext");
void* handle = dlopen ("libreactnativejni.so", RTLD_LAZY);
if (!handle) {
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);
std::string absoluteAppPath(strFileDir);
env->ReleaseStringUTFChars(fileDir , strFileDir);
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
typedef std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> (*get_jsc_context_t)();

View File

@ -6,12 +6,13 @@
#include "../js_init.h"
#include <string>
std::string s_default_realm_directory;
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;
}
}
std::string default_realm_file_directory()
{

View File

@ -105,8 +105,10 @@ std::map<std::string, JSValueRef> &RJSPrototypes(Realm *realm) {
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() {
s_defaultPath = realm::default_realm_file_directory() + "/default.realm";
return s_defaultPath;
}
void RJSSetDefaultPath(std::string path) {

View File

@ -8,8 +8,9 @@
#include <string>
namespace realm {
extern std::string s_default_realm_directory;
namespace realm {
//
// These methods are used internally and must be implemented
// separately for eadh platform