Android NDK:为不同的体系结构编译不同的库

时间:2013-10-14 10:22:28

标签: android android-ndk makefile java-native-interface

我有一个小的c ++库,必须为armeabi和armeabi7a编译。我还有一个非常大的c ++库,只需要为armeabi编译。现在他们正在为两种体系结构编译(使用NDK),但这使我的.apk非常大。是否有可能只针对armeabi编译大型库?我该怎么做?

我的文件夹结构是这样的:

/jni/biglib/
/jni/smalllib/
/jni/Application.mk
/jni/Android.mk

我的/jni/Application.mk文件包含:

APP_ABI := armeabi-v7a armeabi
APP_OPTIM := release

我的root /jni/Android.mk文件结合了每个库的Android.mk文件:

LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDE := $(LOCAL_PATH)/include

include $(addprefix $(LOCAL_PATH)/, $(addsuffix /Android.mk, \
    biglib \
    smalllib \
))

1 个答案:

答案 0 :(得分:4)

绝对有可能。有一些代码片段可以帮助您(没有针对biglib和smallib的Android.mk的确切内容,我无法帮助您)。

1)在APP_ABI中将APP_ABI := armeabi armeabi-v7a更改为Application.mk

2)修改根Android.mk

LOCAL_PATH := $(call my-dir)
LOCAL_C_INCLUDE := $(LOCAL_PATH)/include

# biglib is not built for armeabi-v7a
ifneq "$(TARGET_ARCH_ABI)" "armeabi-v7a"
  include $(LOCAL_PATH)/biglib/Android.mk
endif

# ----- cut here -----
# Place this snippet to every module which needs biglib, or where convenient.
# Now you will link against armeabi version of biglib.
ifeq "$(TARGET_ARCH_ABI)" "armeabi-v7a"
  LOCAL_LDFLAGS += $(LOCAL_PATH)/../obj/local/armeabi/libbigLib.so
endif
# ----- cut here -----

include $(LOCAL_PATH)/smalllib/Android.mk

这就是全部 - 您的apk文件现在不包含libbiglib.so armeabi-v7a