简体   繁体   中英

Building Android NDK app with static library for distribution

I have an Android project, featuring some native code, which use a static library for some Poco-library functions. I have currently linked in the arm7 build of the static library in the make files below. Now if i want to distribute this app on google play, for portatbility i need to include other architectures in the apk to. How do i include for example the static libPocofoundation.a for arm6 and the static libPocoFoundation.a for arm7 to the shared library in the apk?

include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := PocoFoundation
LOCAL_SRC_FILES := Poco/libPocoFoundation.a   #<- How do i set this conditional-
#                                                 or add multiple architectures?
LOCAL_EXPORT_C_INCLUDES := /Users/poco-1.5.1-all/Foundation/include
LOCAL_EXPORT_CFLAGS := -DFOO=1 -fpermissive
LOCAL_EXPORT_LDLIBS := -llog
include $(PREBUILT_STATIC_LIBRARY)

Android.mk

LOCAL_PATH := $(call my-dir)
ROOT_PATH := $(LOCAL_PATH)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_PATH = $(ROOT_PATH)

include $(CLEAR_VARS)
#LOCAL_MODULE_TAGS    := eng
LOCAL_ARM_MODE       := arm
LOCAL_MODULE    := JsonPoco # Your own library.
LOCAL_SRC_FILES := JsonPoco.cpp \


 # Your own library source.
LOCAL_WHOLE_STATIC_LIBRARIES := PocoFoundation \
PocoJSON
LOCAL_LDLIBS     := -llog
LOCAL_CFLAGS     := -DPOCO_ANDROID -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_WSTRING -DPOCO_NO_SHAREDMEMORY
LOCAL_CPPFLAGS   := -frtti -fexceptions 
include $(BUILD_SHARED_LIBRARY)

If I understand well, you want to include different builds of this static library, located in different paths.

As Rajitha said, the first step to support multiple platforms is to mention them in the Application.mk . For example, to support ARMv5/6 and ARMv7:

APP_ABI := armeabi armeabi-v7a

Then in your Android.mk , you'll want to change the path you use for the static library depending on the platform currently being built:

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    LOCAL_SRC_FILES := /path/to/armv-7/libPocofoundation.a
else
    LOCAL_SRC_FILES := /path/to/armv-6/libPocofoundation.a
endif

You can do this if/else condition on more architectures if you want to support x86 for example.

Application.mkAPP_ABI修改为

APP_ABI := all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM