考虑我创建一个包含两个名为JNITestLib.h和JNITestLib.cpp的类的本机库(让我们称之为testLib)。这个库使用另一个由其他人开发的共享库(让我们称之为libotherLib.so),其中包含两个名为OtherLib.cpp和OtherLib.h的类
在我的文件下面
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := otherLib-prebuilt
LOCAL_SRC_FILES := $(LOCAL_PATH)/library/libotherLib.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := testLib
LOCAL_SHARED_LIBRARIES := otherLib-prebuilt
LOCAL_SRC_FILES += com_example_JNITestLib.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
JNITestLib.cpp:
#include "com_example_JNITestLib.h"
#define LOG_TAG "Test"
JNIEXPORT void Java_com_example_JNITestLib_startTest
(JNIEnv *env, jobject)
{
ALOGD( "startTest JNI");
}
JNITestLib.h:
#include <jni.h>
#include "Debug.h"
#include "OtherLib.h" //Problem here!!!!
JNIEXPORT void Java_com_example_JNITestLib_startTest
(JNIEnv *env, jobject);
我的问题是执行后出现以下错误:ndk-build -C [project_path] / app / src / main / jni /:
fatal error: OtherLib: No such file or directory
#include OtherLib.h
^
我还尝试更改我的Android.mk文件,如:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := testLib
LOCAL_SRC_FILES += com_example_JNITestLib.cpp
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -l$(LOCAL_PATH)/library/libotherLib.so
include $(BUILD_SHARED_LIBRARY)
但是得到:
This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the current module
注意我无法获取OtherLib.h,因为它包含在libotherLib.so
中有人有任何想法解决我的问题吗?
答案 0 :(得分:1)
如果要将它们包含在C ++代码中,则需要libotherLib.so的头文件。一旦你有头文件,你应该在Android.mk中添加一行,告诉编译器在哪里寻找包括:
include $(CLEAR_VARS)
LOCAL_MODULE := testLib
LOCAL_SHARED_LIBRARIES := otherLib-prebuilt
LOCAL_SRC_FILES += com_example_JNITestLib.cpp
LOCAL_C_INCLUDES := <path to a directory containing the headers>
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)