简体   繁体   中英

using android ndk to call native function from .so file

I found instructions for how to link and use c/c++ code in Android by utilizing the NDK. But I'm searching how call function from third party .so .

For example your prebuilt library is called "libmy.so"

In the project folder of the project you want to use it:

1) create libmy folder in jni folder ( jni/libmy )

2) copy your libmy.so here

Then, just create a jni/libmy/Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libmy
LOCAL_SRC_FILES := libmy.so
include $(PREBUILT_SHARED_LIBRARY)

Now in your jni/Android.mk you can write:

LOCAL_SHARED_LIBRARIES := libmy

Then when you do ndk-build, it will copy this library in to libs/armeabi/

After that you can use this library in your C++ code.

You just have to put the .so in your libs/armeabi-v7a folder (or whatever other architecture you have compiled for, like armeabi, x86 etc.) and Eclipse will automatically see it and integrate it into the APK.

Then to access any native functions from the .so in your Java code, you just have to declare it as a native function at the top of your class. For example

protected static native void AKUAppInitialize ();

which can then be called anywhere later in the code like

AKUAppInitialize();

如果您有源代码,则必须配置NDK部分:请看本教程

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM