here is code to execute gradle based shared lib
cpp
-----
#include
#include
using namespace std;
extern "C" {
JNIEXPORT jstring JNICALL Java_com_seo_Sample1_stringMethod
(JNIEnv *env, jobject obj, jstring string) {
const char *name = (*env).GetStringUTFChars(string, NULL);
char msg[60] = "Hello ";
jstring result;
strcat(msg, name);
(*env).ReleaseStringUTFChars(string, name);
puts(msg);
result = (*env).NewStringUTF(msg);
return result;
}
}
Java
-----
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.seo;
/**
*
* @author vpilaka
*/
public class Sample1 {
static{
System.loadLibrary("hello");
}
public native String stringMethod(String name);
public static void main(String[] args) {
new Sample1().stringMethod("hi");
}
}
build.gradle
-------------
apply plugin: "cpp"
// You don't need to apply the plugin below if you're already using CUnit or GoogleTest support
apply plugin: TestingModelBasePlugin
task myCustomCheck {
doLast {
println 'Executing my custom check'
}
}
model {
components {
hello(NativeLibrarySpec) {
binaries.all {
// Register our custom check task to all binaries of this component
checkedBy $.tasks.myCustomCheck
cppCompiler.args "-I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include", "-I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/include/darwin"
}
}
}
}
Command Line
------------------
java -cp src/main/java/ -Djava.library.path=/Users/vpilaka/ com.seo.Sample1
Comments