I have a program that needs to execute a libsodium encryption. I found this library libsodium
but I think it needs to be used with NDK. And so I started to read tutorials about NDK but I still don’t know where to start on using this library. If someone could give a hint or very useful stuff to give an idea on how to integrate this library, I would be so happy.
To integrate libsodium into your Android app, you need:
- The libsodium library compiled for your Android platform(s)
- A JNI binding like kalium-jni
If you trust random people on the Internet (which you should not!), download this tarball and extract it into your project source. Otherwise, follow the instructions below to compile it yourself.
You need a Linux box/VM with Android NDK to compile the libsodium shared libraries, and it seems like you need the current git master branch to compile it with the NDK. Once you checked it out, compile the Android library code for ARM, ARMv7 and x86:
./autogen.sh ./dist-build/android-arm.sh # for older ARMv6 devices ./dist-build/android-armv7-a.sh # for the more recent ARMv7 devices ./dist-build/android-x86.sh # for the emulator / x86 devices # Provide the directory names nkd-build expects ln -s libsodium-android-armv6 libsodium-android-armeabi ln -s libsodium-android-armv7-a libsodium-android-armeabi-v7a ln -s libsodium-android-i686 libsodium-android-x86
To compile kalium, you will need SWIG installed. Then, you need to generate the SWIG C wrapper, compile the libkaliumjni native code for your target platform(s), install it into your app libs/ directory and include the JAR.
In the kalium-jni/jni sub-directory, create the SWIG wrapper and the native libkaliumjni.so for your host (it will be needed for testing the JAR):
jni/Android.mk and replace
/installs/ with wherever you have compiled libsodium, and
$(TARGET_ARCH_ABI) then run in the kalium-jni directory:
ndk-build APP_ABI=armeabi,armeabi-v7a,x86 [...] [x86] Install : libkaliumjni.so => libs/x86/libkaliumjni.so [armeabi] Install : libkaliumjni.so => libs/armeabi/libkaliumjni.so [armeabi-v7a] Install : libkaliumjni.so => libs/armeabi-v7a/libkaliumjni.so
libs/ directory contains the native kalium libraries. Copy it into your Android project.
Finally, you need to compile the kalium JAR:
mvn clean install
It should end up in
~/.m2/repository/org/abstractj/kalium/kalium-jni/1.0.0-SNAPSHOT/kalium-jni-1.0.0-SNAPSHOT.jar. Copy that to your
libs directory as well. It is accompanied by javadoc and sources JARs, which you can add into Eclipse to get the references.