I am trying to integrate the libsodium library in an Android project. I am using Android Studio (0.5.8) with the gradle (0.9) and android build (19.1) tools. I compiled libsodium with scripts that can be found in the library. I get four preBuild libraries (.so files) for different architectures (arm, arm-v7a, mips and x86). I put these files in jniLibs folder. I declare in my build.gradle that I am using the NDK and configure the path in the local.properties file.
In this version of gradle, there is no need to write a make file ( http://ph0b.com/android-studio-gradle-and-ndk-integration/ )
I declare some of my own functions in my activity after a static call:
static { System.loadLibrary("sodium"); } public final static native String sodium_version_string(); onCreate() { ... Log.d(getClass().getName(), "Sodium version:" + sodium_version_string()); }
Logcat Output:
05-29 23:14:10.538 481-1569/system_process I/ActivityManager﹕ Start proc com.example.myapplication2.app.x86 for activity com.example.myapplication2.app.x86/com.example.myapplication2.app.MainActivity: pid=1584 uid=10056 gids={50056, 1028} 05-29 23:14:10.554 1584-1584/com.example.myapplication2.app.x86 D/dalvikvm﹕ Trying to load lib /data/app-lib/com.example.myapplication2.app.x86-2/libsodium.so 0xa4ed8520 05-29 23:14:10.562 1584-1584/com.example.myapplication2.app.x86 D/dalvikvm﹕ Added shared lib /data/app-lib/com.example.myapplication2.app.x86-2/libsodium.so 0xa4ed8520 05-29 23:14:10.562 1584-1584/com.example.myapplication2.app.x86 D/dalvikvm﹕ No JNI_OnLoad found in /data/app-lib/com.example.myapplication2.app.x86-2/libsodium.so 0xa4ed8520, skipping init 05-29 23:14:10.578 1584-1584/com.example.myapplication2.app.x86 W/dalvikvm﹕ No implementation found for native Lcom/example/myapplication2/app/MainActivity;.sodium_version_string:()Ljava/lang/String; 05-29 23:14:10.578 1584-1584/com.example.myapplication2.app.x86 D/AndroidRuntime﹕ Shutting down VM 05-29 23:14:10.578 1584-1584/com.example.myapplication2.app.x86 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4c46648) 05-29 23:14:10.578 1584-1584/com.example.myapplication2.app.x86 E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.UnsatisfiedLinkError: Native method not found: com.example.myapplication2.app.MainActivity.sodium_version_string:()Ljava/lang/String; at com.example.myapplication2.app.MainActivity.sodium_version_string(Native Method) at com.example.myapplication2.app.MainActivity.onCreate(MainActivity.java:28)
Is there something else to declare in another file? Is it really potassium-jni? How can this lib be included in a project?
Thanks.
android android-gradle android-ndk libsodium
Albert
source share