mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 13:33:13 -07:00
Init Chiaki Lib on Android
This commit is contained in:
parent
7fb4c67f33
commit
103df69d29
2 changed files with 47 additions and 2 deletions
|
@ -3,3 +3,6 @@ cmake_minimum_required(VERSION 3.2)
|
||||||
|
|
||||||
add_library(chiaki-jni SHARED src/main/cpp/chiaki-jni.c)
|
add_library(chiaki-jni SHARED src/main/cpp/chiaki-jni.c)
|
||||||
target_link_libraries(chiaki-jni chiaki-lib)
|
target_link_libraries(chiaki-jni chiaki-lib)
|
||||||
|
|
||||||
|
find_library(ANDROID_LIB_LOG log)
|
||||||
|
target_link_libraries(chiaki-jni "${ANDROID_LIB_LOG}")
|
|
@ -1,7 +1,49 @@
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
#include <android/log.h>
|
||||||
|
|
||||||
#include <chiaki/common.h>
|
#include <chiaki/common.h>
|
||||||
|
#include <chiaki/log.h>
|
||||||
|
|
||||||
|
#define LOG_TAG "Chiaki"
|
||||||
|
|
||||||
|
static void log_cb_android(ChiakiLogLevel level, const char *msg, void *user)
|
||||||
|
{
|
||||||
|
int prio;
|
||||||
|
switch(level)
|
||||||
|
{
|
||||||
|
case CHIAKI_LOG_DEBUG:
|
||||||
|
prio = ANDROID_LOG_DEBUG;
|
||||||
|
break;
|
||||||
|
case CHIAKI_LOG_VERBOSE:
|
||||||
|
prio = ANDROID_LOG_VERBOSE;
|
||||||
|
break;
|
||||||
|
case CHIAKI_LOG_INFO:
|
||||||
|
prio = ANDROID_LOG_INFO;
|
||||||
|
break;
|
||||||
|
case CHIAKI_LOG_WARNING:
|
||||||
|
prio = ANDROID_LOG_ERROR;
|
||||||
|
break;
|
||||||
|
case CHIAKI_LOG_ERROR:
|
||||||
|
prio = ANDROID_LOG_ERROR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
prio = ANDROID_LOG_INFO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
__android_log_print(prio, LOG_TAG, "%s", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChiakiLog log_ctx;
|
||||||
|
|
||||||
|
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||||
|
{
|
||||||
|
chiaki_log_init(&log_ctx, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, log_cb_android, NULL);
|
||||||
|
CHIAKI_LOGI(&log_ctx, "Loading Chiaki Library");
|
||||||
|
ChiakiErrorCode err = chiaki_lib_init();
|
||||||
|
CHIAKI_LOGI(&log_ctx, "Chiaki Library Init Result: %s\n", chiaki_error_string(err));
|
||||||
|
return JNI_VERSION_1_2;
|
||||||
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_com_metallic_chiaki_lib_Chiaki_stringFromJNI(JNIEnv *env, jobject thiz)
|
JNIEXPORT jstring JNICALL Java_com_metallic_chiaki_lib_Chiaki_stringFromJNI(JNIEnv *env, jobject thiz)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue