Merge branch 'al-android-aar' of https://github.com/realm/realm-js into al-android-aar

This commit is contained in:
Nabil Hachicha 2016-01-11 23:18:05 +00:00
commit 529ea5cf70
6 changed files with 20 additions and 18 deletions

View File

@ -8,6 +8,7 @@
#include "com_reacttests_RealmReactAndroid.h"
#include "JSCExecutor.h"
#include "js_init.h"
#include "platform.hpp"
#include <unordered_map>
/*
@ -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<JSContextRef, facebook::react::JSCExecutor*> (*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());

View File

@ -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)

View File

@ -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());

View File

@ -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

View File

@ -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

View File

@ -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