实现NDK的pre-build实例

实现NDK的pre-build实例

项目中要用到既存的老代码,所以就需要用到JNI,这时问题就来了。

如何在NDK中让JNI的代码引用static library或shared library?


1. 对于static library,问题比较简单,直接上Android.mk。

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := test-jni
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_SRC_FILES := test-jni.c
LOCAL_LDLIBS := -l log -ldl $(LOCAL_PATH)/../TestStaticLib/libtest.a
include $(BUILD_SHARED_LIBRARY)


2. 对于shared library,参考stackoverflow上的建议和ndk中的pre-build文档,结论如下,
注意:以下需要ndk 1.5及以上版本.

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := test-prebuild
LOCAL_SRC_FILES := libtest.so
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := test-jni
LOCAL_SRC_FILES := test_jni.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := test-prebuild
include $(BUILD_SHARED_LIBRARY)


Java测的代码,需要先用loadlibray(“既存的shared library”, test),再loadlibrary("ndk编译出来的jni library", test-jni);


阅读更多
个人分类: android ndk
上一篇android性能测试工具之dumpstate
下一篇如何分析Android的内存使用量
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭