fix: use the build static instead of build shared, add a free which works question mark(?)

This commit is contained in:
0x330a 2022-11-30 11:48:41 +11:00
parent a7554428d5
commit ad00aeac4a
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
4 changed files with 38 additions and 9 deletions

View File

@ -24,6 +24,19 @@ class ExampleInstrumentedTest {
fun jni_accessible() { fun jni_accessible() {
val userProfile = UserProfile.newInstance() val userProfile = UserProfile.newInstance()
assertNotNull(userProfile) assertNotNull(userProfile)
userProfile.free()
}
@Test
fun jni_setting_getting() {
val userProfile = UserProfile.newInstance()
val newName = "test"
println("Name being set via JNI call: $newName")
userProfile.setName(newName)
val nameFromNative = userProfile.getName()
assertEquals(newName, nameFromNative)
println("Name received by JNI call: $nameFromNative")
userProfile.free()
} }
} }

View File

@ -13,8 +13,8 @@ project("session_util")
# or SHARED, and provides the relative paths to its source code. # or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you. # You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK. # Gradle automatically packages shared libraries with your APK.
set(STATIC_BUNDLE ON)
set(BUILD_SHARED_LIBS ON CACHE BOOL "") #set(BUILD_SHARED_LIBS ON CACHE BOOL "")
add_subdirectory(../../../libsession-util libsession) add_subdirectory(../../../libsession-util libsession)
add_library( # Sets the name of the library. add_library( # Sets the name of the library.

View File

@ -35,4 +35,20 @@ Java_network_loki_messenger_libsession_1util_UserProfile_setName(
jstring newName) { jstring newName) {
auto profile = ptrToProfile(env, obj); auto profile = ptrToProfile(env, obj);
profile->set_name(env->GetStringUTFChars(newName, nullptr)); profile->set_name(env->GetStringUTFChars(newName, nullptr));
}
extern "C"
JNIEXPORT jstring JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_getName(JNIEnv *env, jobject obj) {
auto profile = ptrToProfile(env, obj);
auto name = profile->get_name();
jstring returnString = env->NewStringUTF(name->c_str());
return returnString;
}
extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_UserProfile_free(JNIEnv *env, jobject obj) {
auto profile = ptrToProfile(env, obj);
delete profile;
} }

View File

@ -2,22 +2,22 @@ package network.loki.messenger.libsession_util
sealed class ConfigBase(protected val /* yucky */ pointer: Long) { sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
companion object {
init {
System.loadLibrary("session_util")
}
}
} }
class UserProfile(pointer: Long): ConfigBase(pointer) { class UserProfile(pointer: Long): ConfigBase(pointer) {
companion object { companion object {
init { init {
System.loadLibrary("session_util") System.loadLibrary("session_util")
} }
external fun newInstance(): UserProfile external fun newInstance(): UserProfile
} }
var lastError: String? = null
external fun setName(newName: String) external fun setName(newName: String)
external fun getName(): String
external fun free()
} }