how to setup a prebuilt library in jni for android?

hi, i need to use a prebuilt library in my native code so i am placing the library following the example in ndk/samples/native-activity. Below is the structure. Please some one help me out with this error, dsplink.h can not be found. Thanks in advance :)

Answers


I thin Vladimir was on the right track. But don't keep the static lib in the obj folder since that one is delete every run, instead create a jni/modules/precompiled or something and put the stuff there...

what you have is a precompiled static lib. that's what the .a file is. it's meant to add it to a compilation process so that it'll be in the final binary. so what you should have is :

#
# DSPLINK
#
include $(CLEAR_VARS)
LOCAL_MODULE    := dsplink
LOCAL_SRC_FILES  := [path-to-prebuilt-lib]/libdsplink.a
LOCAL_EXPORT_C_INCLUDES := [path-to-dsplink-headers-folder]
include $(PREBUILT_STATIC_LIBRARY)

and also dont forget to include it for the linker in the project .. so below this section in the main shared lib add this line :

LOCAL_STATIC_LIBRARIES := dsplink

Your C file includes dsplink.h file. If you have it, you should add the full path to this file in LOCAL_C_INCLUDES, e.g.

LOCAL_MODULE     := jnihello
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inlcudes

By the way, if dsplink.a file is prebuilt, you will be on the safe side to keep it outside of the libs/ folder, so that make clean does not delete it. You can use something like

LOCAL_LDFLAGS += $(LOCAL_PATH)/prebuilt/dsplink.a

to help the linker find the file.


libmath-prebuilt.so is a prebuilt library which has some functions which are used by buyya_read.c. First generate libmath-prebuilt.so using ndk-build and keep in jni folder where buyya_read.c is kept in ur project in elcipse.

Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := math-prebuilt
LOCAL_SRC_FILES = libmath-prebuilt.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := buyya_read
LOCAL_SRC_FILES := buyya_read.c
LOCAL_LDLIBS    := -llog
LOCAL_SHARED_LIBRARIES := math-prebuilt
include $(BUILD_SHARED_LIBRARY)

You see the project directory structure in below image.


You should define prebuilt library dsplink in your Android.mk before jnihello project:

#
# DSPLINK
#
include $(CLEAR_VARS)
LOCAL_MODULE    := dsplink
LOCAL_SRC_FILES  := [path]/libs/armeabi/libdsplink.so
LOCAL_EXPORT_C_INCLUDES := [directory-with-dsplink.h-file]
include $(PREBUILT_STATIC_LIBRARY)
...
# jnihello

Need Your Help

Scala Implicit Ordering

scala implicit

Is there a way for me to define the same implicit ordering for two different classes?