David Karlsson
David Karlsson

Reputation: 9696

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)

Upvotes: 1

Views: 2224

Answers (2)

mbrenon
mbrenon

Reputation: 4941

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.

Upvotes: 4

Rajitha Siriwardena
Rajitha Siriwardena

Reputation: 2759

Modify the APP_ABI in your Application.mk to

APP_ABI := all

Upvotes: 0

Related Questions