mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
feat. JNI
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(MeoAssistantArknights)
|
||||
|
||||
option(BUILD_JNI "build jni" OFF)
|
||||
option(BUILD_TEST "build a demo" OFF)
|
||||
|
||||
include_directories(include 3rdparty/include)
|
||||
@@ -34,6 +35,15 @@ endif ()
|
||||
|
||||
target_link_libraries(MeoAssistant ${OpenCV} ${PaddleOCR_LIB} ${Penguin_LIB} ${ZLIB})
|
||||
|
||||
if (BUILD_JNI)
|
||||
find_package(JNI REQUIRED)
|
||||
include_directories(${JNI_INCLUDE_DIRS})
|
||||
|
||||
set(JNI_SRC src/Java/jni/meoasst_jni.cpp)
|
||||
add_library(MeoAssistantJni SHARED ${JNI_SRC})
|
||||
target_link_libraries(MeoAssistantJni MeoAssistant)
|
||||
endif(BUILD_JNI)
|
||||
|
||||
if (BUILD_TEST)
|
||||
add_executable(test tools/TestCaller/main.cpp)
|
||||
target_link_libraries(test MeoAssistant)
|
||||
|
||||
62
src/Java/jni/meoasst_jni.cpp
Normal file
62
src/Java/jni/meoasst_jni.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
|
||||
#define LOG "maa_jni"
|
||||
#define LOG_D(...) __android_log_print(ANDROID_LOG_DEBUG, LOG, __VA_ARGS__)
|
||||
#define LOG_I(...) __android_log_print(ANDROID_LOG_INFO, LOG, __VA_ARGS__)
|
||||
#define LOG_W(...) __android_log_print(ANDROID_LOG_WARN, LOG, __VA_ARGS__)
|
||||
#define LOG_E(...) __android_log_print(ANDROID_LOG_ERROR, LOG, __VA_ARGS__)
|
||||
#define LOG_F(...) __android_log_print(ANDROID_LOG_FATAL, LOG, __VA_ARGS__)
|
||||
#else
|
||||
#define LOG_D(...)
|
||||
#define LOG_I(...)
|
||||
#define LOG_W(...)
|
||||
#define LOG_E(...)
|
||||
#define LOG_F(...)
|
||||
#endif
|
||||
|
||||
#include "AsstCaller.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_maa_create(JNIEnv* env, jclass c, jstring jstr_dirname)
|
||||
{
|
||||
LOG_D(__FUNCTION__);
|
||||
|
||||
if (env == NULL) {
|
||||
return (jlong)NULL;
|
||||
}
|
||||
|
||||
const char* cstr_dirname = NULL;
|
||||
if (jstr_dirname) {
|
||||
cstr_dirname = env->GetStringUTFChars(jstr_dirname, NULL);
|
||||
}
|
||||
|
||||
asst::Assistant* p_asst = AsstCreate(cstr_dirname);
|
||||
LOG_D("after AsstCreate, p_asst = %p", p_asst);
|
||||
|
||||
if (cstr_dirname) {
|
||||
env->ReleaseStringUTFChars(jstr_dirname, cstr_dirname);
|
||||
}
|
||||
|
||||
return (jlong)p_asst;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_maa_destroy(JNIEnv* env, jclass c, jlong jlong_asst)
|
||||
{
|
||||
LOG_D(__FUNCTION__);
|
||||
|
||||
if (env == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
AsstDestroy((asst::Assistant*)jlong_asst);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user