在.a文件中调用库方法
问题描述:
我在Android Studio 2.1.3上。在.a文件中调用库方法
我有静态库二进制中某文件:
libconfig.a
我有我需要调用库方法签名:
CLIENT_ConfigIPCWifi( szDeviceSN,szSSID,szSSIDPassword,nWaitTime);
问题:我该如何调用该方法?
答
您的app/src/main/jni文件夹中需要一个Android.mk文件。它应该是这样的
LOCAL_PATH := $(call my-dir)
# This block is to make the NDK aware of your static library
include $(CLEAR_VARS)
LOCAL_MODULE := libconfig
LOCAL_SRC_FILES := path/to/libconfig/libconfig.a
include $(PREBUILT_STATIC_LIBRARY)
# This block is to build your C++ code that will call the method in the static library
include $(CLEAR_VARS)
LOCAL_MODULE := ThatWillCallTheMethod
LOCAL_SRC_FILES := cppFileThatWillCallTheMethod.cpp
LOCAL_STATIC_LIBRARIES := libconfig.a
include $(BUILD_SHARED_LIBRARY)
在你jni
文件夹,您将有:cppFileThatWillCallTheMethod.cpp
。并在该文件中,您将调用CLIENT_ConfigIPCWifi(szDeviceSN,szSSID,szSSIDPassword,nWaitTime);不知何故,你将不得不知道你需要包含libconfig.a中的哪些头文件。
希望这会有所帮助!