[DllImport("sqleet", EntryPoint= "execute_test")]
public static extern string execute_test(string path);
//java
[DllImport("native-lib", EntryPoint = "Java_com_km_demo_myapplication_MainActivity_stringFromJNI")]
public extern static IntPtr stringFromJNI(IntPtr env, IntPtr thiz);
//java
[DllImport("hello", EntryPoint = "Java_com_km_demo_myapplication_hello_add")] //省略掉lib前缀和.so 后缀
//public static extern int add(IntPtr env, IntPtr thiz, int i, int j);
[DllImport("hello")] //省略掉lib前缀和.so 后缀
public static extern int add( int i, int j);
[DllImport("hello")] //省略掉lib前缀和.so 后缀
public static extern string getString(string str);
//java 字符串
var zz = stringFromJNI(System.IntPtr.Zero, System.IntPtr.Zero);
Java.Lang.String ss = Java.Lang.Object.GetObject(zz, JniHandleOwnership.TransferLocalRef);
//普通字符串
string str = getString("abc");
java
#include
#include
extern "C" JNIEXPORT jstring JNICALL Java_com_km_demo_myapplication_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
//
// Created by Administrator on 2020/3/18.
//
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class com_km_demo_myapplication_hello */
#ifndef _Included_com_km_demo_myapplication_hello
#define _Included_com_km_demo_myapplication_hello
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_km_demo_myapplication_hello
* Method: add
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_com_km_demo_myapplication_hello_add
(JNIEnv *, jobject, jint i, jint j){
return i+j;
}
int add(int i, int j){
return i+j;
}
#ifdef __cplusplus
}
#endif
#endif