0

I'm struggling to get a native Android application correctly link against a custom shared object built in the same AOSP tree.

I have a shared object built with

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)

It gets built and installed as the mm command invocation

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

Once I try to buil a native application linked against the newly created .so with the following Android.mk

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)

I get:

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.

I noticed two things: the shared library is installed under X/out/lib as libscanengine and not libscanenegine.so as it is required by the native application.

I have to manually copy the .so everytime, which is stupid since all of this should be handled in some way by the Android build system.

Furthermore, the LOCAL_EXPORT_C_INCLUDES directive does not work. Does it work only with PREBUILT_SHARED_OBJECTS?

Android version is 2.3, there is no Java involved, everything is built under AOSP.

Thank you
j

1
  • INCLUDES are for compiling, not linking. Your -L might have worked, but it should have been LDFLAGS not CFLAGS. You have to figure out and fix the misnaming though. Dec 17, 2013 at 12:59

2 Answers 2

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

does not work because it should read

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

or

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

But this does not explain why LOCAL_SHARED_LIBRARIES is not working. What commands do you use to build?

0

Whilst not a good solution, if the libscanengine target can't be found implicitly via AOSP, then you can always include it manually, like so.

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

Regarding why the shared object won't build correctly, a hacky solution is providing a static object directly after the shared one which references it, in the Android.mk. For instance, this I adapted from an existing jpeg port. What I wanted was a shared library I could work with in a separate compilation step, but it wouldn't be built unless it was required by something.

$(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)

Whilst neither of these are true solutions, as they don't address the underlying reason behind your problems, they may aid you, as they did me, in getting stuff working quickly and automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.