Commit 5d21c6d7 authored by Marek Kotewicz's avatar Marek Kotewicz
Browse files

linking android library dynamically works!

parent f4622826
# rust output file
*.a
*.so
.externalNativeBuild
# OSX
#
......
......@@ -115,7 +115,7 @@ android {
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def versionCodes = ["armeabi-v7a": 1, "x86": 2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
......@@ -123,6 +123,12 @@ android {
}
}
}
externalNativeBuild {
ndkBuild {
path 'src/main/jniLibs/Android.mk'
}
}
}
dependencies {
......
......@@ -3,7 +3,7 @@ package com.nativesigner;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;
/**
* Created by marek on 20/02/2017.
......@@ -20,12 +20,15 @@ public class EthkeyBridge extends ReactContextBaseJavaModule {
}
@ReactMethod
public void brainWalletAddress(String seed, Callback callback) {
callback.invoke("hello from java");
public void brainWalletAddress(String seed, Promise promise) {
int a = hello();
promise.resolve("hello from java " + a + " sa");
}
@ReactMethod
public void brainWalletSecret(String seed, Callback callback) {
callback.invoke("hello from java");
public void brainWalletSecret(String seed, Promise promise) {
promise.resolve("hello from java");
}
private static native int hello();
}
......@@ -42,6 +42,7 @@ public class MainApplication extends Application implements ReactApplication {
@Override
public void onCreate() {
super.onCreate();
System.loadLibrary("signer");
SoLoader.init(this, /* native exopackage */ false);
}
}
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libsigner
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libsigner.so
include $(PREBUILT_SHARED_LIBRARY)
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
#Mon Mar 06 10:46:53 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
......@@ -10,9 +10,12 @@ ethkey = { git = "https://github.com/ethcore/parity" }
rlp = { git = "https://github.com/ethcore/parity" }
tiny-keccak = "1.1"
#[target.'cfg(target_os="android")'.dependencies]
jni = { git = "https://github.com/prevoty/jni-rs", default-features = false }
[lib]
name = "signer"
crate-type = ["staticlib"]
crate-type = ["staticlib", "cdylib"]
# https://github.com/DaGenix/rust-crypto/issues/383
[replace]
......
ARCHS = i386-apple-ios x86_64-apple-ios armv7-apple-ios armv7s-apple-ios aarch64-apple-ios
LIB = libsigner.a
ARCHS_IOS = i386-apple-ios x86_64-apple-ios armv7-apple-ios armv7s-apple-ios aarch64-apple-ios
ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi i686-linux-android
LIB=libsigner.a
all: $(LIB)
all: ios android
.PHONY: $(ARCHS)
$(ARCHS): %:
ios: $(LIB)
android: $(ARCHS_ANDROID)
.PHONY: $(ARCHS_IOS)
$(ARCHS_IOS): %:
cargo build --target $@ --release
.PHONY: $(ARCHS_ANDROID)
$(ARCHS_ANDROID): %:
cargo build --target $@ --release
$(LIB): $(ARCHS)
lipo -create -output $@ $(foreach arch,$(ARCHS),$(wildcard target/$(arch)/release/$(LIB)))
$(LIB): $(ARCHS_IOS)
lipo -create -output $@ $(foreach arch,$(ARCHS_IOS),$(wildcard target/$(arch)/release/$(LIB)))
#! /bin/bash
mkdir -p ../../android/app/src/main/jniLibs
mkdir -p ../../android/app/src/main/jniLibs/x86
mkdir -p ../../android/app/src/main/jniLibs/arm64-v8a
mkdir -p ../../android/app/src/main/jniLibs/armeabi-v7a
cp ./target/i686-linux-android/release/libsigner.so ../../android/app/src/main/jniLibs/x86/libsigner.so
cp ./target/aarch64-linux-android/release/libsigner.so ../../android/app/src/main/jniLibs/arm64-v8a/libsigner.so
cp ./target/armv7-linux-androideabi/release/libsigner.so ../../android/app/src/main/jniLibs/armeabi-v7a/libsigner.so
#!/bin/sh
# ios
multirust add-target stable i386-apple-ios
multirust add-target stable x86_64-apple-ios
multirust add-target stable armv7-apple-ios
multirust add-target stable armv7s-apple-ios
multirust add-target stable aarch64-apple-ios
# android
multirust add-target stable aarch64-linux-android
multirust add-target stable armv7-linux-androideabi
multirust add-target stable i686-linux-android
......@@ -94,6 +94,27 @@ pub unsafe extern fn keccak256(data: *mut StringPtr) -> *mut String {
Box::into_raw(Box::new(res.to_hex()))
}
extern crate jni;
use self::jni::sys::jint;
#[no_mangle]
#[allow(non_snake_case)]
pub unsafe extern fn Java_com_nativesigner_EthkeyBridge_hello() -> jint {
4
}
#[cfg(target_os = "android")]
#[allow(non_snake_case)]
pub mod android {
extern crate jni;
use self::jni::sys::jint;
#[no_mangle]
pub unsafe extern fn Java_com_nativesigner_EthkeyBridge_helloFromRust() -> jint {
5
}
}
#[cfg(test)]
mod tests {
use super::safe_rlp_item;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment