如何限制Android.mk编译模块只生成64位库

How to restrict Android.mk to compile a module to generate only 64bit library

我能够在 android 中为 arm 平台集成一个 64 位预构建库“x”,当我尝试在需要的模块中调用该库时,该模块将为 32 位和 64 位库编译失败,提及 32 位找不到“x”的库。 /out/target/product/xxxx/system/lib64/libxxxx.所以

  1. 预建库 makefile
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_SRC_FILES := libfoo.so
    LOCAL_MODULE := libfoo
    LOCAL_MODULE_SUFFIX := .so
    LOCAL_MODULE_CLASS := SHARED_LIBRARIES
    LOCAL_MODULE_PATH := $(TARGET_OUT)/lib64
    LOCAL_MODULE_TAGS := debug
    LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
    include $(BUILD_PREBUILT
  1. 链接模块 Makefile
    include $(CLEAR_VARS)
    LOCAL_SRC_FILES := \
        test.c 
        
    LOCAL_SHARED_LIBRARIES := \
        liblog \
        libcutils 

    LOCAL_C_INCLUDES += $(LOCAL_PATH)/include

    ifeq ($(TARGET_ARCH),arm64)
       LOCAL_SHARED_LIBRARIES   += libfoo.so
    endif

    LOCAL_CFLAGS += -Wall -Werror 
    LOCAL_MODULE := vtest
    LOCAL_MODULE_RELATIVE_PATH := test
    LOCAL_MODULE_TAGS := optional
    include $(BUILD_SHARED_LIBRARY)
ninja: error: 'out/target/product/xxxx/obj_arm/SHARED_LIBRARIES/libxxxx_intermediates/export_includes', needed by 'out/target/product/xxxx/obj_arm/SHARED_LIBRARIES/yyyyy/import_includes', missing and no known rule to make it

我想限制链接模块只为 64 位构建而不是为 32 位构建,我尝试了以下但没有工作 ifeq ($(TARGET_ARCH),arm64) LOCAL_SHARED_LIBRARIES += libxxx 结尾

请提供解决此问题的建议

来自 https://source.android.com/setup/develop/64-bit-builds :

LOCAL_MODULE_TARGET_ARCH

将此变量设置为架构列表,例如arm x86 arm64。如果正在构建的体系结构在该列表中,则当前模块包含在构建系统中。

LOCAL_MODULE_UNSUPPORTED_TARGET_ARCH

这个变量与LOCAL_MODULE_TARGET_ARCH相反。如果正在构建的体系结构不在该列表中,则当前模块包含在构建系统中。

最后通过以下更改修复并且有效

LOCAL_MODULE_TARGET_ARCH := arm64
LOCAL_LDLIBS += $(LOCAL_PATH)/libfoo.so
                                                        

而不是

 ifeq ($(TARGET_ARCH),arm64)
   LOCAL_SHARED_LIBRARIES   += libfoo.so
endif

@maurice 你是部分正确的感谢你的输入它 LOCAL_LDLIBS 与 Target Arch

一起帮助