feat: add linux native library support for libsession to enable junit testing (might not be the best way)

This commit is contained in:
0x330a
2023-10-04 09:59:10 +11:00
parent fb2a7a8fed
commit e419024f6b
8 changed files with 98 additions and 29 deletions

View File

@@ -42,18 +42,25 @@ add_library( # Sets the name of the library.
# Provides a relative path to your source file(s).
${SOURCES})
if (LINUX)
message("Linux machine detected")
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include;$ENV{JAVA_HOME}/include/linux")
find_package(JNI REQUIRED)
include_directories(${JAVA_INCLUDE_PATH})
endif()
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
#find_library( # Sets the name of the path variable.
# log-lib
#
# # Specifies the name of the NDK library that
# # you want CMake to locate.
# log)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
@@ -66,4 +73,5 @@ target_link_libraries( # Specifies the target library.
libsession::crypto
# Links the target library to the log library
# included in the NDK.
${log-lib})
)
#${log-lib})

View File

@@ -203,7 +203,6 @@ inline jobject iterator_as_java_stack(JNIEnv *env, const session::config::UserGr
} else if (auto* community = std::get_if<session::config::community_info>(&item)) {
serialized = serialize_community_info(env, *community);
} else if (auto* closed = std::get_if<session::config::group_info>(&item)) {
LOGD("Item is closed group");
serialized = serialize_closed_group_info(env, *closed);
}
if (serialized != nullptr) {
@@ -219,8 +218,6 @@ JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_UserGroupsConfig_all(JNIEnv *env, jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto conf = ptrToUserGroups(env, thiz);
bool isFin = conf->begin().done();
LOGD("Group iterator has more: %d", isFin);
jobject all_stack = iterator_as_java_stack(env, conf->begin(), conf->end());
return all_stack;
}

View File

@@ -2,6 +2,7 @@
#define SESSION_ANDROID_UTIL_H
#include <jni.h>
#include <mutex>
#include <array>
#include <optional>
#include "session/types.hpp"
@@ -11,13 +12,13 @@
#include "session/config/profile_pic.hpp"
#include "session/config/user_groups.hpp"
#include "session/config/expiring.hpp"
#include <android/log.h>
//#include <android/log.h>
#define LOG_TAG "libsession-jni"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
//#define LOG_TAG "libsession-jni"
//#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
//#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
//#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
//#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
namespace util {
extern std::mutex util_mutex_;