Android原生共享库安装路径

时间:2013-12-17 11:37:01

标签: android c++ android-ndk android-source

我正在努力让原生Android应用程序正确链接到同一AOSP树中构建的自定义共享对象。

我有一个用

构建的共享对象
LOCAL_SRC_FILES += \
   src/libscanengine.c

LOCAL_C_INCLUDES += $(LOCAL_PATH) 
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include/
LOCAL_C_INCLUDES += kernel/include/

#every module depending on us will 
#automagically have this included
LOCAL_EXPORT_C_INCLUDES := \
  $(LOCAL_PATH)/include

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libscanengine 
LOCAL_PRELINK_MODULE := false

include $(BUILD_SHARED_LIBRARY)

它是作为mm命令调用构建和安装的

build/core/dynamic_binary.mk:141: warning: overriding commands for target `.so'
build/core/dynamic_binary.mk:118: warning: ignoring old commands for target `.so'
build/core/shared_library.mk:54: warning: overriding commands for target `.so'
build/core/dynamic_binary.mk:141: warning: ignoring old commands for target `.so'
No private recovery resources for TARGET_DEVICE X
No recovery.fstab for TARGET_DEVICE X
make: Circular .so <- .so dependency dropped.
make: Circular .so <- out/target/product/X/symbols/system/lib/libscanengine dependency dropped.
make: Circular .so <- .so dependency dropped.
target Non-prelinked: libscanengine (out/target/product/X/symbols/system/lib/libscanengine)
target Strip: libscanengine (out/target/product/X/obj/lib/libscanengine)
Install: out/target/product/X/system/lib/libscanengine.so

尝试使用以下Android.mk

构建针对新创建的.so链接的本机应用程序
LOCAL_SRC_FILES := \
    src/mores.c

LOCAL_C_INCLUDES += \
    $(LOCAL_PATH) 
LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/include/

#not working: commented out
#LOCAL_LDLIBS += \
    -lscanengine
#LOCAL_C_FLAGS += \
    -L../../out/target/product/X/system/lib/

LOCAL_SHARED_LIBRARIES := \
    libscanengine

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := mores

include $(BUILD_EXECUTABLE)

我明白了:

make: *** No rule to make target `out/target/product/X/obj/lib/libscanengine.so', needed by `out/target/product/X/obj/EXECUTABLES/mores_intermediates/LINKED/mores'.  Stop.

我注意到两件事:共享库安装在X / out / lib下作为 libscanengine 而不是 libscanenegine.so ,因为本机应用程序需要它。 / p>

我必须每次都手动复制.so,这是愚蠢的,因为所有这些都应该由Android构建系统以某种方式处理。

此外,LOCAL_EXPORT_C_INCLUDES指令不起作用。它只适用于PREBUILT_SHARED_OBJECTS吗?

Android版本为2.3,没有涉及Java,一切都是在AOSP下构建的。

谢谢你      Ĵ

2 个答案:

答案 0 :(得分:0)

LOCAL_C_FLAGS += \
    -L../../out/target/product/X/system/lib/

不起作用,因为它应该读取

LOCAL_LDFLAGS += \
    -Lout/target/product/X/system/lib

LOCAL_LDFLAGS += \
    -L$(LOCAL_PATH)/out/target/product/X/system/lib

但这并不能解释为什么LOCAL_SHARED_LIBRARIES无效。你用什么命令来构建?

答案 1 :(得分:0)

虽然不是一个好的解决方案,但如果无法通过AOSP隐式找到libscanengine目标,那么你总是可以手动包含它,就像这样。

include $(AOSP_ROOT)/PATH/TO/libscanengine/Android.mk

关于为什么共享对象不能正确构建,一个hacky解决方案是在Android.mk中直接在引用它的共享对象之后提供静态对象。例如,我改编自现有的jpeg端口。我想要的是一个共享库,我可以在一个单独的编译步骤中使用它,但它不会被构建,除非它被某些东西需要。

$(call my-dir)
include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm

LOCAL_SRC_FILES := \
    jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
    jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
    jcphuff.c jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
    jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
    jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c jdphuff.c \
    jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
    jfdctint.c jidctflt.c jidctred.c jquant1.c \
    jquant2.c jutils.c jmemmgr.c \
    jmem-android.c

# the assembler is only for the ARM version, don't break the Linux sim
ifneq ($(TARGET_ARCH),arm)
ANDROID_JPEG_NO_ASSEMBLER := true
endif

# temp fix until we understand why this broke cnn.com
#ANDROID_JPEG_NO_ASSEMBLER := true

ifeq ($(strip $(ANDROID_JPEG_NO_ASSEMBLER)),true)
LOCAL_SRC_FILES += jidctint.c jidctfst.c
else
LOCAL_SRC_FILES += jidctint.c jidctfst.S
endif

LOCAL_CFLAGS += -I"$(LOCAL_PATH)/./include" -DAVOID_TABLES
LOCAL_CFLAGS += -O3 -fstrict-aliasing -fprefetch-loop-arrays
#LOCAL_CFLAGS += -march=armv6j

LOCAL_MODULE:= jpeg

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := jpeg2
LOCAL_STATIC_LIBRARIES := jpeg

include $(BUILD_SHARED_LIBRARY)

虽然这些都不是真正的解决方案,因为它们没有解决问题背后的根本原因,但他们可能会帮助您,就像他们一样,让您快速自动地工作。