Friday, August 2, 2019

Android: Link third party libraries to your service

AOSP make file structure does not make it easy to link external libraries to your custom service. Here I am outlining a specific way to achieve this.

Create 'libs' folder under your service implementation and put the '.a' or '.so' files in there.
And add Android.mk under 'libs' folder

LOCAL_PATH := $(call my-dir)
PREBUILT_PATH := $(LOCAL_PATH)

include $(CLEAR_VARS)
LOCAL_MODULE        := libMyhal
LOCAL_MODULE_OWNER  := mycompany
LOCAL_MODULE_TAGS   := optional
LOCAL_MODULE_CLASS  := STATIC_LIBRARIES
LOCAL_MODULE_SUFFIX := .a
LOCAL_SRC_FILES     := libMyhal.a
include $(BUILD_PREBUILT)


If you have '.so' file change STATIC_LIBRARIES to SHARED_LIBRARIES.

Now in your service Android.mk file
Add this line
LOCAL_STATIC_LIBRARIES := libMyhal

Also to the end of the file add
include $(call all-makefiles-under,$(LOCAL_PATH))
This line will ensure to invoke the makefile created under 'libs' folder.

No comments:

Post a Comment