在android jni项目中导入本地子模块

时间:2013-11-26 10:57:24

标签: android c++ android-ndk

我正在尝试用结构创建android jni项目。

我想创建静态库test_module并将其包含在主共享库监视器

jni目录包含

jni
 |-> MonitorPreview.cpp
 |-> Processor.cpp
 |-> Android.mk
 |-> test_module
      |-> IModule.cpp
      |-> TestModule.cpp
      |-> Android.mk

其中jni / Android.mk

LOCAL_PATH                             := $(call my-dir)
MY_ROOT                                := $(LOCAL_PATH)

include $(call all-subdir-makefiles)

include $(CLEAR_VARS)
LOCAL_PATH                             := $(MY_ROOT)

LOCAL_MODULE                           := monitor
LOCAL_C_INCLUDES                       := $(LOCAL_PATH)/test_module
LOCAL_SRC_FILES                        := MonitorPreview.cpp \
                                          Processor.cpp
LOCAL_STATIC_LIBRARIES                 := test_module
LOCAL_LDLIBS                           := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
$(call import-module, test_module)

JNI / test_module / Android.mk

LOCAL_PATH                             := $(call my-dir)

$(info    local path = $(LOCAL_PATH))

include $(CLEAR_VARS)
LOCAL_MODULE                           := test_module
LOCAL_SRC_FILES                        := IModule.cpp \
                                          TestModule.cpp
LOCAL_EXPORT_C_INCLUDES                := $(LOCAL_PATH)

include $(PREBUILD_STATIC_LIBRARY)

ndk-build因错误而失败

/home/pavel/android_dev/android-ndk-r8e/ndk-build all 
local path = jni/test_module
SharedLibrary  : libmonitor.so
/home/pavel/android_dev/android-ndk-r8e/toolchains/arm-linux-androideabi-   4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux- androideabi/bin/ld: ./obj/local/armeabi-v7a/objs/monitor/Processor.o: in function    hrm::Processor::Processor():jni/Processor.cpp:15: error: undefined reference to   'hrm::TestModule::TestModule()'
`collect2: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libmonitor.so] Error 1`

抱歉英语不好。

请帮忙。

1 个答案:

答案 0 :(得分:0)

我找到了答案。见diff's

JNI / Android.mk

LOCAL_PATH                             := $(call my-dir)
MY_ROOT                                := $(LOCAL_PATH)

include $(call all-subdir-makefiles)

include $(CLEAR_VARS)
LOCAL_PATH                             := $(MY_ROOT)

LOCAL_MODULE                           := monitor
LOCAL_C_INCLUDES                       := $(LOCAL_PATH)/test_module
LOCAL_SRC_FILES                        := MonitorPreview.cpp \
                                          Processor.cpp
LOCAL_LDLIBS                           := -llog -landroid
include $(BUILD_SHARED_LIBRARY)
$(call import-module test_module)

JNI / test_module / Android.mk

LOCAL_PATH                             := $(call my-dir)

$(info    local path = $(LOCAL_PATH))

include $(CLEAR_VARS)
LOCAL_MODULE                           := test_module
LOCAL_SRC_FILES                        := IModule.cpp \
                                          TestModule.cpp
LOCAL_EXPORT_C_INCLUDES                := $(LOCAL_PATH)

include $(BUILD_STATIC_LIBRARY)