android jni wrapper,c - Android NDK - Error Linking Shared library and JNI Wrapper - Stack Overflow

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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值