Android的NDK模块依赖另一个模块 [英] Android NDK module that is dependant on another module

查看:271
本文介绍了Android的NDK模块依赖另一个模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我采用的是Android NDK编写的Andr​​oid项目。在项目中,我用两个prebuilt共享库(GpkgSDK和spatialite),建设两个共享库(WFSHelpers和com_example_gpkgviewer_jni_WKTConverter)。与该应用程序的Java平交互的唯一的库是com_example_gpkgviewer_jni_WKTConverter库。

I have an android project written using the Android NDK. Within the project, I am using two prebuilt shared libraries(GpkgSDK and spatialite) and building two more shared libraries(WFSHelpers and com_example_gpkgviewer_jni_WKTConverter). The only library that interacts with the Java level of the application is the com_example_gpkgviewer_jni_WKTConverter library.

库之间的依赖关系如下图所示:

The dependencies between the libraries are shown below:


  • WFSHelpers取决于GpkgSDK和spatialite

  • com_example_gpkgviewer_jni_WKTConverter取决于WFSHelpers

这是我遇到的问题是,当我尝试运行NDK的构建,我试图建立com_example_gpkgviewer_jni_WKTConverter库时得到了很多未定义的引用。其他库成功建立。我通常会解决这些未定义的引用的方式是通过在我com_example_gpkgviewer_jni_WKTConverter模块定义如下:

The issue that I am having is that when I try to run ndk-build, I am getting a lot of undefined references when attempting to build the com_example_gpkgviewer_jni_WKTConverter library. The other libraries are successfully built. The way I would normally resolve these undefined references is by including the following in my com_example_gpkgviewer_jni_WKTConverter module definition :

LOCAL_SHARED_LIBRARY := WFSHelpers

我不确定是否我还需要包括该WFSHelpers依赖于像这样的库:

I am unsure as to whether I would also need to include the libraries that the WFSHelpers is dependent on like so:

LOCAL_SHARED_LIBRARY := WFSHelpers GpkgSDK spatialite

我也尝试过不同的顺序,像这样,但它似乎并没有解决我的问题:

I have also tried them in a different order like so but it does not seem to resolve my issue:


  • LOCAL_SHARED_LIBRARY:= GpkgSDK spatialite WFSHelpers

我的Application.mk包含如下:

My Application.mk is included below:

NDK_TOOLCHAIN_VERSION := 4.8
# APP_STL := stlport_shared  --> does not seem to contain C++11 features
APP_STL := gnustl_shared

# Enable c++11 extentions in source code
APP_CPPFLAGS += -std=c++11
APP_CPPFLAGS += -frtti 
APP_CPPFLAGS += -fexceptions

APP_MODULES := GpkgSDK spatialite WFSHelpers com_example_gpkgviewer_jni_WKTConverter

APP_ABI := armeabi armeabi-v7a

我的Andr​​oid.mk如下图所示:

My Android.mk is shown below:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GpkgSDK
LOCAL_SRC_FILES := libMP.so
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include \
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_SRC_FILES := spatialamal/prebuilt/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_EXPORT_C_INCLUDES :=     spatialamal/headers/spatialite \
                            spatialamal/headers
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := WFSHelpers
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_SRC_FILES := \
GPKGReader/Debug.h \
GPKGReader/DLLExport.h \
GPKGReader/DBQueryResult.cpp \
GPKGReader/GeoPackageDB.cpp \
GPKGReader/GPKGReader.cpp \
GPKGReader/order32.h \
GPKGReader/SpecDefinitions.h \
GPKGReader/WKBGenericGeometry.cpp \
GPKGReader/WKBLineString.cpp \
GPKGReader/WKBMultiLineString.cpp \
GPKGReader/WKBMultiPolygon.cpp \
GPKGReader/WKBPoint.cpp \
GPKGReader/WKBPolygon.cpp \
GPKGDataLayer/GPKGDataLayer.cpp
LOCAL_SHARED_LIBRARIES := GpkgSDK spatialite
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_MODULE    := com_example_gpkgviewer_jni_WKTConverter
LOCAL_SRC_FILES := com_example_gpkgviewer_jni_WKTConverter.cpp
LOCAL_SHARED_LIBRARY := WFSHelpers GpkgSDK spatialite
include $(BUILD_SHARED_LIBRARY)

这是我收到未定义引用错误的示例如下:

An example of the undefined reference errors that I am getting is shown below:

[armeabi] SharedLibrary  : libcom_example_gpkgviewer_jni_WKTConverter.so
jni/com_example_gpkgviewer_jni_WKTConverter.cpp:59: error: undefined reference
o 'WKBGenericGeometry::readInt32(unsigned char, unsigned char*, unsigned int)'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libcom_example_gpkgviewer_jni_WKTConverter.so]
Error 1

code的范围内com_example_gpkgviewer_jni_WKTConverter.cpp导致此错误的行如下所示:

The line of code within com_example_gpkgviewer_jni_WKTConverter.cpp that causes this error is shown below:

*id_arg = WKBGenericGeometry::readInt32(byte_order, &(bytes[4]), length - 4);

我如何能解决依赖任何建议。

Any suggestions on how I can resolve the dependencies.

推荐答案

试图让这个建立了好半天后,我终于能够得到它的工作。虽然,我不太清楚的区别是什么,所以任何人谁可以摆脱一盏灯,这是值得欢迎这样做。我的问题是,我对其他库的依赖关系。文档状态如下:

After attempting to get this to build for ages, I have finally been able to get it to work. Although, I am not quite sure what the differences are, so anyone who can shed a light on this is welcome to do so. My issue was that I had dependencies on other libraries. The documentation states the following:

LOCAL_SHARED_LIBRARIES
The list of shared libraries modules this module depends on at runtime. This is necessary at link time and to embed the corresponding information in the generated file.


LOCAL_LDLIBS
The list of additional linker flags to be used when building your shared library or executable. This is useful to pass the name of specific system libraries with the '-l' prefix. For example, the following will tell the linker to generate a module that links to /system/lib/libz.so at load time:
LOCAL_LDLIBS := -lz
See STABLE-APIS for the list of exposed system libraries you can linked against with this NDK release.
NOTE: This is ignored for static libraries, and ndk-build will print a warning if you define it in such a module.

因此​​,在我的Andr​​oid.mk文件,我只好用LOCAL_LDLIBS代替LOCAL_SHARED_LIBRARIES指示的依赖关系。

Thus in my Android.mk file, I had to use LOCAL_LDLIBS instead of LOCAL_SHARED_LIBRARIES to indicate the dependencies.

我的新Android.mk如下图所示:

My new Android.mk is as shown below:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GpkgSDK
LOCAL_SRC_FILES := libMP.so
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include \
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_SRC_FILES := spatialamal/prebuilt/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_EXPORT_C_INCLUDES :=     spatialamal/headers/spatialite \
                            spatialamal/headers
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := WFSHelpers
LOCAL_SRC_FILES := \
GPKGReader/Debug.h \
GPKGReader/DLLExport.h \
GPKGReader/DBQueryResult.cpp \
GPKGReader/GeoPackageDB.cpp \
GPKGReader/GPKGReader.cpp \
GPKGReader/order32.h \
GPKGReader/SpecDefinitions.h \
GPKGReader/WKBGenericGeometry.cpp \
GPKGReader/WKBLineString.cpp \
GPKGReader/WKBMultiLineString.cpp \
GPKGReader/WKBMultiPolygon.cpp \
GPKGReader/WKBPoint.cpp \
GPKGReader/WKBPolygon.cpp \
GPKGDataLayer/GPKGDataLayer.cpp
LOCAL_LDLIBS := libs/$(TARGET_ARCH_ABI)/libGpkgSDK.so
LOCAL_LDLIBS += libs/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := com_example_gpkgviewer_jni_WKTConverter
LOCAL_SRC_FILES := com_example_gpkgviewer_jni_WKTConverter.cpp
LOCAL_LDLIBS := libs/$(TARGET_ARCH_ABI)/libWFSHelpers.so
LOCAL_LDLIBS += libs/$(TARGET_ARCH_ABI)/libGpkgSDK.so
include $(BUILD_SHARED_LIBRARY)

因为我不能完全肯定LOCAL_LDLIBS和LOCAL_SHARED_LIBRARIES之间有什么区别,我将离开这个答案开一会儿。如果有人能为我提供的说明,请做。如果没有,给它一段时间后所接受,我将标志着这个答案。谢谢!

I shall leave this answer open for a while as I am not entirely sure what the difference between LOCAL_LDLIBS and LOCAL_SHARED_LIBRARIES is. If anyone can provide me with an explanation, please do. If not, I shall mark this answer as accepted after giving it some time. Thanks !

这篇关于Android的NDK模块依赖另一个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆