java调用C++:
#include <jni.h>
//导出c函数格式
extern "C" JNIEXPORT
//供JNI调用
JNICALL
函数名格式 Java_包名_类名_函数名(包名.替换为_)
Java_com_example_getapplist_MainActivity_stringFromJNI
包名:com_example_getapplist 类名:MainActivity. 函数名:stringFromJNI
#include <jni.h>
#include <string>
//导出c函数格式
extern "C" JNIEXPORT jstring
//供JNI调用
JNICALL
//函数名格式 Java_包名_类名_函数名(包名.替换为_)
Java_com_example_getapplist_MainActivity_stringFromJNI(JNIEnv *env, //JNI环境jobject //类对象) {//string对象std::string hello = "Hello from C++";//string转换为jstringreturn env->NewStringUTF(hello.c_str());
}
C++ Jni CMakeList.txt
cmake_minimum_required(VERSION 3.22.1)
project("getapplist")
add_library(${CMAKE_PROJECT_NAME}