I have embarked on a project to create a Nativescript wrapper for a Java library in order to harness its functionalities for a Nativescript application. Despite the lack of detailed articles on this topic, I have decided to turn this into a plugin wrapper as there doesn't seem to be a straightforward method within the Nativescript app itself.
The specific Java library I am integrating is Libsignal-protocol-java. Following the cloning of the Nativescript Plugin Seed, I have added this Java library as a dependency:
src/platforms/android/include.gradle
android {
}
dependencies {
compile 'org.whispersystems:signal-protocol-android:2.3.0+'
}
Identifying the package housing the method I wish to access within the Java source was my next step:
KeyHelper.generateRegistrationId();
(source). It was noted in an article that specifying the package during class and method instantiation is essential.
Following that, I configured my libsignal-protocol.common.ts
like so in an attempt to utilize the native method:
src/libsignal-protocol.common.ts
import { Observable } from 'tns-core-modules/data/observable';
export class Common extends Observable {
constructor() {
// does not work
let test1 = new org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId();
// does not work
let test2 = org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId();
console.log(test1);
console.log(test2);
}
}
To my disappointment, the logger revealed the following error:
System.err: Error: java.lang.Exception: Failed resolving method generateRegistrationId on class org.whispersystems.libsignal.util.KeyHelper
At this point, I am uncertain about the next steps to take. Opting to create a wrapper for this impressive Java library seemed more secure and organized than attempting to use their JavaScript library via browserify, especially considering the required features not supported by Nativescript.
Any guidance or recommendations would be greatly appreciated! For reference, here are some articles I came across that have guided me to my current status on this matter.
Sources
- Using libsodium in Android/Nativescript
- How to use JAR file in Nativescript