接着上一篇的内容。
上一篇讲的是动态库中调用静态库
这一篇讲的是 动态库中调用动态库
第一个要编译的动态库:
PrintTest.h:
extern int Add(int x, int y);
PrintTest.c
#include "PrintTest.h"
int Add(int x, int y)
{
return x + y;
}
Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := print_share
LOCAL_SRC_FILES := PrintTest.c
include $(BUILD_SHARED_LIBRARY)
运行ndk-build
编译出来的文件在 \obj\local\armeabi 文件夹,而不是libs文件夹那个!特别要注意。。。。。。。。。。
现在来编译第二个动态库,他来调用第一个动态库
user.c:
#include "PrintTest.h"
#include <jni.h>
int UseTest( int x , int y )
{
return Add(x,y);
}
Android.mk:
LOCAL_PATH:= $(call my-dir)
# 需要把动态库导入
#
include $(CLEAR_VARS)
LOCAL_MODULE := print_share
LOCAL_SRC_FILES := libprint_share.so
include $(PREBUILT_SHARED_LIBRARY)
# 第二个为动态库,在动态库中使用我们编译的动态库
include $(CLEAR_VARS)
LOCAL_MODULE := libuse
LOCAL_SRC_FILES := Use.c
LOCAL_SHARED_LIBRARIES := libprint_share
include $(BUILD_SHARED_LIBRARY)