fixed example, add Relinker to load JNI lib

This commit is contained in:
Nabil Hachicha 2015-12-11 17:45:17 +00:00 committed by Ari Lazier
parent ac32f97f8d
commit 8965aa80f7
7 changed files with 29 additions and 5 deletions

View File

@ -183,7 +183,7 @@ dependencies {
compile 'com.squareup.okio:okio:1.6.0'
compile 'org.webkit:android-jsc:r174650'
compile "com.facebook.react:react-native:0.16.+"
compile 'com.github.KeepSafe:ReLinker:1.1'
testCompile "junit:junit:${JUNIT_VERSION}"
testCompile "org.powermock:powermock-api-mockito:${POWERMOCK_VERSION}"

View File

@ -5,14 +5,18 @@ 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 com.getkeepsafe.relinker.ReLinker;
import java.util.Map;
import java.util.HashMap;
import android.widget.Toast;
public class RealmReactAndroid extends ReactContextBaseJavaModule {
private static final String DURATION_SHORT_KEY = "SHORT";
private static final String DURATION_LONG_KEY = "LONG";
public RealmReactAndroid(ReactApplicationContext reactContext) {
super(reactContext);
getDefaultRealmFileDirectory();
ReLinker.loadLibrary(reactContext, "realmreact");
}
@Override
@ -20,5 +24,23 @@ 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);
return constants;
}
@ReactMethod
public void show(String message, int duration) {
StringBuilder sb = new StringBuilder("String from Java: ")
.append(message)
.append("\n")
.append("String from JNI: ")
.append(getDefaultRealmFileDirectory());
Toast.makeText(getReactApplicationContext(), sb.toString(), duration).show();
}
public static native String getDefaultRealmFileDirectory();
}

View File

@ -17,5 +17,6 @@ allprojects {
repositories {
mavenLocal()
jcenter()
maven { url "https://jitpack.io" }
}
}

View File

@ -76,4 +76,5 @@ dependencies {
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:0.16.+"
compile 'com.reacttests:app-debug@aar'
compile 'com.github.KeepSafe:ReLinker:1.1'
}

View File

@ -23,7 +23,6 @@ import com.reacttests.RealmReactAndroid;
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
private ReactInstanceManager mReactInstanceManager;
private ReactRootView mReactRootView;

View File

@ -22,5 +22,6 @@ allprojects {
flatDir{
dirs 'lib'
}
maven { url "https://jitpack.io" }
}
}

View File

@ -17,7 +17,7 @@ var RealmReactAndroid = require('NativeModules').RealmReactAndroid;
var Demo = React.createClass({
buttonClicked: function() {
RealmReactAndroid.show("Hello Zepp");
RealmReactAndroid.show("Hello Zepp", RealmReactAndroid.LONG);
},
render: function() {
return (