How to compile native C library and daemon using Android.mk ?

To compile any c library inside android, we need to write an Android.mk makefile, for reference please check below,

$ mkdir external/mysource
$ cd external/mysource

In below makefile Android.mk we assume, you have a C library code in library_source.c file and application using this c library in main.c

$ vim Android.mk

To compile as Shared Library,

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := library_source.c

LOCAL_C_INCLUDES :=$(LOCAL_PATH)
LOCAL_CFLAGS := -O2 -g -W -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H
LOCAL_MODULE := libmylib
LOCAL_MODULE_TAGS := debug
LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils libm
include $(BUILD_SHARED_LIBRARY)

To compile as executable, using above shared library ( append to above Android.mk )

include $(CLEAR_VARS)
LOCAL_SRC_FILES := main.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS := -O2 -g -W -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_CONFIG_H
LOCAL_MODULE := main-exececutable
LOCAL_MODULE_TAGS := debug
LOCAL_SYSTEM_SHARED_LIBRARIES := libc libcutils libm
LOCAL_SHARED_LIBRARIES := libmylib
include $(BUILD_EXECUTABLE)

Change red color as per your library, source,

To compile, above source, type from top android source ” make libmylib” i.e. whatever name you have given in LOCAL_MODULE.

Simple CRUD in Vue.JS Web Applicati... x
Simple CRUD in Vue.JS Web Application | Vue.JS Projects with Source Code

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux