Change package name fixes #204

This commit is contained in:
Nabil Hachicha 2016-01-28 15:09:36 +00:00
parent dd9242e584
commit 1e4c905cdc
11 changed files with 6 additions and 413 deletions

View File

@ -54,7 +54,7 @@ android {
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.reactexample"
applicationId "io.realm.react.example"
minSdkVersion 16
targetSdkVersion 22
versionCode 1

View File

@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactexample">
package="io.realm.react.example">
<uses-permission android:name="android.permission.INTERNET" />

View File

@ -1,113 +0,0 @@
package com.reactexample;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactPackage;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.soloader.SoLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.reacttests.RealmReactAndroid;
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
private ReactInstanceManager mReactInstanceManager;
private ReactRootView mReactRootView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new AnExampleReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "ReactExample", null);
setContentView(mReactRootView);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU && mReactInstanceManager != null) {
mReactInstanceManager.showDevOptionsDialog();
return true;
}
return super.onKeyUp(keyCode, event);
}
@Override
public void onBackPressed() {
if (mReactInstanceManager != null) {
mReactInstanceManager.onBackPressed();
} else {
super.onBackPressed();
}
}
@Override
public void invokeDefaultOnBackPressed() {
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
if (mReactInstanceManager != null) {
mReactInstanceManager.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
if (mReactInstanceManager != null) {
mReactInstanceManager.onResume(this, this);
}
}
class AnExampleReactPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new RealmReactAndroid(reactContext));
return modules;
}
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}
}

View File

@ -133,12 +133,6 @@ android {
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
moduleName "reactnativejni"
}
buildConfigField 'boolean', 'IS_INTERNAL_BUILD', 'false'
}
sourceSets.main {
@ -162,7 +156,6 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.nanohttpd:nanohttpd:2.2.0'
compile 'com.facebook.react:react-native:0.18.0-patched'
compile 'org.webkit:android-jsc:r174650'
}
apply from: 'release.gradle'

View File

@ -1,30 +1,3 @@
<!-- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reacttests">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.reacttests">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.realm.react">
<application />
</manifest>

View File

@ -1,126 +0,0 @@
package com.reacttests;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import java.util.Map;
import java.util.HashMap;
import android.widget.Toast;
import com.facebook.react.bridge.Callback;
import android.util.Log;
import java.io.IOException;
import java.util.Map;
import fi.iki.elonen.NanoHTTPD;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.CountDownLatch;
import com.facebook.soloader.SoLoader;
public class RealmReactAndroid extends ReactContextBaseJavaModule {
private static final String DURATION_SHORT_KEY = "SHORT";
private static final String DURATION_LONG_KEY = "LONG";
private String filesDirPath;
private static final int DEFAULT_PORT = 8082;
private AndroidWebServer webServer;
private long rpcServerPtr;
private Handler handler = new Handler(Looper.getMainLooper());
public RealmReactAndroid(ReactApplicationContext reactContext) {
super(reactContext);
try {
filesDirPath = getReactApplicationContext().getFilesDir().getCanonicalPath();
} catch (IOException e) {
throw new IllegalStateException(e);
}
SoLoader.loadLibrary("realmreact");
}
@Override
public String getName() {
return "RealmReactAndroid";
}
@Override
public Map<String, Object> getConstants() {
long contexts = injectRealmJsContext(filesDirPath);
Log.i("RealmReactAndroid", "Initialized " + contexts + " contexts");
if (contexts == 0) {// we're running in Chrome debug mode
startWebServer();
}
return new HashMap<>();
}
@Override
public void onCatalystInstanceDestroy() {
if (webServer != null) {
Log.i("RealmReactAndroid", "Stopping the webserver");
webServer.stop();
}
}
private void startWebServer() {
rpcServerPtr = setupChromeDebugModeRealmJsContext();
webServer = new AndroidWebServer(DEFAULT_PORT);
try {
webServer.start();
Log.i("RealmReactAndroid", "Starting WebServer, Host: " + webServer.getHostname() + " Port: " + webServer.getListeningPort());
} catch (IOException e) {
e.printStackTrace();
}
}
// WebServer
class AndroidWebServer extends NanoHTTPD {
public AndroidWebServer(int port) {
super(port);
}
public AndroidWebServer(String hostname, int port) {
super(hostname, port);
}
@Override
public Response serve(IHTTPSession session) {
final String cmdUri = session.getUri();
Log.v("AndroidWebServer", "Session Uri: " + cmdUri + " Mehtod: " + session.getMethod().name());
final HashMap<String, String> map = new HashMap<String, String>();
try {
session.parseBody(map);
} catch (IOException e) {
e.printStackTrace();
} catch (ResponseException e) {
e.printStackTrace();
}
final String json = map.get("postData");
Log.v("AndroidWebServer", "Post Data: \n" + json + "\n Thread id: " + Thread.currentThread().getName());
final String[] jsonResponse = new String[1];
final CountDownLatch latch = new CountDownLatch(1);
// Process the command on the UI thread
handler.post(new Runnable() {
@Override
public void run() {
jsonResponse[0] = processChromeDebugCommand(rpcServerPtr, cmdUri, json);
latch.countDown();
}
});
try {
latch.await();
Response response = newFixedLengthResponse(jsonResponse[0]);
response.addHeader("Access-Control-Allow-Origin", "http://localhost:8081");
return response;
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
}
}
// fileDir: path of the internal storage of the application
private native long injectRealmJsContext(String fileDir);
// responsible for creating the rpcServer that will accept thw chrome Websocket command
private native long setupChromeDebugModeRealmJsContext();
// this receives one command from Chrome debug, & return the processing we should post back
private native String processChromeDebugCommand(long rpcServerPointer, String cmd, String args);
}

View File

@ -24,7 +24,7 @@ LOCAL_SRC_FILES := \
src/js_schema.cpp \
src/rpc.cpp \
src/android/platform.cpp \
src/android/com_reacttests_RealmReactAndroid.cpp \
src/android/io_realm_react_RealmReactAndroid.cpp \
src/object-store/index_set.cpp \
src/object-store/list.cpp \
src/object-store/object_schema.cpp \

View File

@ -1,98 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_reacttests_API */
#include <dlfcn.h>
#include <iostream>
#include <sstream>
#include "com_reacttests_RealmReactAndroid.h"
#include "js_init.h"
#include "rpc.hpp"
#include "platform.hpp"
#include "shared_realm.hpp"
#include <unordered_map>
#include <android/log.h>
namespace facebook {
namespace react {
class JSCExecutor;
}
}
/*
* Class: com_reacttests_RealmReactAndroid
* Method: injectRealmJsContext
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
(JNIEnv *env, jclass, jstring fileDir)
{
__android_log_print(ANDROID_LOG_DEBUG, "JSRealm", "Java_com_reacttests_RealmReactAndroid_injectRealmJsContext");
void* handle = dlopen ("libreactnativejni.so", RTLD_LAZY);
if (!handle) {
return 0;
//return env->NewStringUTF("Cannot open library");
}
// Getting the internal storage path for the application
const char* strFileDir = env->GetStringUTFChars(fileDir , NULL);
realm::set_default_realm_file_directory(strFileDir);
env->ReleaseStringUTFChars(fileDir , strFileDir);
__android_log_print(ANDROID_LOG_DEBUG, "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)();
get_jsc_context_t get_jsc_context = (get_jsc_context_t) dlsym(handle, "get_jsc_context");
if (get_jsc_context != NULL) {
// clearing previous instances
realm::Realm::s_global_cache.clear();
std::unordered_map<JSContextRef, facebook::react::JSCExecutor*> s_globalContextRefToJSCExecutor = get_jsc_context();
for (auto pair : s_globalContextRefToJSCExecutor) {
RJSInitializeInContext(pair.first);
}
return s_globalContextRefToJSCExecutor.size();
//std::stringstream msg;
//msg << "Got the globalContext map, size=" << s_globalContextRefToJSCExecutor.size();
//return env->NewStringUTF(msg.str().c_str());
} else {
return 0;
// return env->NewStringUTF("Cannot find symbol get_jsc_context");
}
}
/*
* Class: com_reacttests_RealmReactAndroid
* Method: setupChromeDebugModeRealmJsContext
*/
static realm_js::RPCServer *s_rpc_server;
JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_setupChromeDebugModeRealmJsContext
(JNIEnv *, jclass)
{
__android_log_print(ANDROID_LOG_VERBOSE, "JSRealm", "Java_com_reacttests_RealmReactAndroid_setupChromeDebugModeRealmJsContext");
if (s_rpc_server) {
delete s_rpc_server;
}
s_rpc_server = new realm_js::RPCServer();
return (jlong)s_rpc_server;
}
/*
* Class: com_reacttests_RealmReactAndroid
* Method: processChromeDebugCommand
*/
JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_processChromeDebugCommand
(JNIEnv *env, jclass, jlong rpc_server_ptr, jstring chrome_cmd, jstring chrome_args)
{
__android_log_print(ANDROID_LOG_VERBOSE, "JSRealm", "Java_com_reacttests_RealmReactAndroid_processChromeDebugCommand");
const char* cmd = env->GetStringUTFChars(chrome_cmd, NULL);
const char* args = env->GetStringUTFChars(chrome_args, NULL);
realm_js::json json = realm_js::json::parse(args);
realm_js::json response = s_rpc_server->perform_request(cmd, json);
env->ReleaseStringUTFChars(chrome_cmd, cmd);
env->ReleaseStringUTFChars(chrome_args, args);
return env->NewStringUTF(response.dump().c_str());
}

View File

@ -1,36 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_reacttests_API */
#ifndef _Included_com_reacttests_RealmReactAndroid
#define _Included_com_reacttests_RealmReactAndroid
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_reacttests_RealmReactAndroid
* Method: injectRealmJsContext
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_injectRealmJsContext
(JNIEnv *, jclass, jstring);
/*
* Class: com_reacttests_RealmReactAndroid
* Method: setupChromeDebugModeRealmJsContext
*/
JNIEXPORT jlong JNICALL Java_com_reacttests_RealmReactAndroid_setupChromeDebugModeRealmJsContext
(JNIEnv *, jclass);
/*
* Class: com_reacttests_RealmReactAndroid
* Method: processsetupChromeDebugCommand
*/
JNIEXPORT jstring JNICALL Java_com_reacttests_RealmReactAndroid_processChromeDebugCommand
(JNIEnv *, jclass, jlong, jstring, jstring);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.reacttests.RealmReactAndroid;
import io.realm.react.RealmReactAndroid;
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {

2
vendor/PEGTL vendored

@ -1 +1 @@
Subproject commit 3c4128a7e7e1288eb746418ea60c41477358f26a
Subproject commit 2c835cb58073351e373e260f45ac2e148ef3b718