fix: compile issues in session_util.cpp and trying to fix native android builds

This commit is contained in:
0x330a 2022-11-30 11:06:37 +11:00
parent 6593c40ab1
commit a7554428d5
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
6 changed files with 32 additions and 23 deletions

View File

@ -17,9 +17,9 @@ android {
cppFlags "--std=c++17"
}
}
ndk {
abiFilters 'x86_64', 'arm64-v8a' // ,'x86', 'armeabi-v7a' TODO: remove after the native library works properly with targets
}
// ndk {
// abiFilters 'x86_64', 'arm64-v8a' ,'x86', 'armeabi-v7a'
// }
}
buildTypes {

@ -1 +1 @@
Subproject commit e52fc314e5a5659de7c2bb60bb29dc52b80b9ace
Subproject commit e98c2d383cf5e28f665b1b2c782791987eae0544

View File

@ -1,13 +1,11 @@
package network.loki.messenger.libsession_util
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
@ -24,7 +22,8 @@ class ExampleInstrumentedTest {
@Test
fun jni_accessible() {
assertEquals("Hello from C++", NativeLib().stringFromJNI())
val userProfile = UserProfile.newInstance()
assertNotNull(userProfile)
}
}

View File

@ -39,8 +39,6 @@ find_library( # Sets the name of the path variable.
# you want CMake to locate.
log)
# Add the libsession-util library here
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

View File

@ -2,31 +2,34 @@
#include <string>
#include "session/config/user_profile.hpp"
session::config::ConfigBase* ptrToConfigBase(JNIEnv *env, jobject obj) {
jclass baseClass = env->FindClass("network/loki/messenger/libsession_util/ConfigBase");
jfieldID pointerField = env->GetFieldID(baseClass, "pointer", "J");
return (session::config::ConfigBase*) env->GetLongField(obj, pointerField);
}
session::config::UserProfile* ptrToProfile(JNIEnv* env, jobject obj) {
jclass configClass = env->FindClass("network/loki/messenger/libsession_util/Config");
jclass configClass = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
jfieldID pointerField = env->GetFieldID(configClass, "pointer", "J");
return (session::config::UserProfile*) reinterpret_cast<long>(env->GetLongField(obj, pointerField));
return (session::config::UserProfile*) env->GetLongField(obj, pointerField);
}
extern "C" JNIEXPORT jobject JNICALL
Java_network_loki_messenger_libsession_1util_Config_00024Companion_newInstance(
Java_network_loki_messenger_libsession_1util_UserProfile_00024Companion_newInstance(
JNIEnv* env,
jobject /*this*/) {
jobject) {
auto* profile = new session::config::UserProfile();
jclass configClass = env->FindClass("network/loki/messenger/libsession_util/Config");
jobject newConfig = env->AllocObject(configClass);
jfieldID pointerField = env->GetFieldID(configClass, "pointer", "J");
env->SetLongField(newConfig, pointerField, reinterpret_cast<jlong>(profile));
jclass userClass = env->FindClass("network/loki/messenger/libsession_util/UserProfile");
jmethodID constructor = env->GetMethodID(userClass, "<init>", "(J)V");
jobject newConfig = env->NewObject(userClass, constructor, reinterpret_cast<jlong>(profile));
return newConfig;
}
extern "C" JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_Config_setName(
Java_network_loki_messenger_libsession_1util_UserProfile_setName(
JNIEnv* env,
jobject obj,
jstring newName) {

View File

@ -1,9 +1,18 @@
package network.loki.messenger.libsession_util
data class Config(private val /* yucky */ pointer: Long) {
sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
}
class UserProfile(pointer: Long): ConfigBase(pointer) {
companion object {
external fun newInstance(): Config
init {
System.loadLibrary("session_util")
}
external fun newInstance(): UserProfile
}
var lastError: String? = null