I'm trying to link a Shared Library that I generated with the NDK-Standalone toolchain on a different build machine. Then using that specific .so I put it on Android Studio. From there I created a jni.h file using javah which then helped me write the .c JNI for the function calls.
ndk-build does compile and seems to work correctly but when trying to run the application on the phone I get a error at
static {
System.loadLibrary("testLib")
}
Saying that could not find testLib.so even though it is generated and in the libs/armeabi-v7a/testLib.so directory
CURRENT ERROR:
01-31 14:41:53.779 19024-19024/com.jolopy.testing_02 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jolopy.testing_02, PID: 19024
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.jolopy.testing_02-2/base.apk"],nativeLibraryDirectories=[/data/app/com.jolopy.testing_02-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "testLib.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.jolopy.testing_02.TestLib.(TestLib.java:6)
at com.jolopy.testing_02.MainActivity.onCreate(MainActivity.java:18)
How I built the .so file:
arm-linux-androideabi-gcc -c -fPIC testLib.c -o test.o
arm-linux-androideabi-gcc test.o -o testing.so
From there I wrote a JNI wrapper class using javah which generated the testing_Android.h file. Which from there generated the testing_Android.c JNI wrapper that I'm using to call functions from my testLib.c library:
#include "testLib.h"
//Including Machine Generated Header
#include "testing_Android.h"
#include
JNIEXPORT void JNICALL Java_com_jolopy_testing_102_TestLib_testinglib_1Initialize
(JNIEnv *env, jobject obj){
(void)env;
(void)obj;
testing_Initialize();
}
JNIEXPORT jint JNICALL Java_com_jolopy_testing_102_TestLib_testinglib_1Get_1Count
(JNIEnv *env, jobject obj){
(void)env;
(void)obj;
return(testing_Get_Count());
}
JNIEXPORT jint JNICALL Java_com_jolopy_testing_102_TestLib_testinglib_1Get_1CurrentName
(JNIEnv *env, jobject obj, jlong ptr, jint x){
(void)env;
(void)obj;
return (testing_Get_CurrentName((char *)ptr , (int)x));
}
From there I have 5 files in the jni folder in Android which is where I run the ndk-build command from:
testing.so | testing_Android.h | testing_Android.c | Application.mk | Android.mk
Android.mk:
LOCAL_PATH :=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := testLib
LOCAL_SRC_FILES := testing.so
LOCAL_EXPORT_C_INCLUDES := testing_Android.c
include $(PREBUILT_SHARED_LIBRARY)
Application.mk:
APP_PLATFORM := android-19
APP_ABI := armeabi-v7a
Any suggestions or faults in my progress that you might see that I don't would be greatly appreciated.
-Cheers!