Dependencies between 2 Android.mk files - android

I have 2 Android.mk files with the first one building a bunch of libraries and the second one builds another library, but needs the first one to be complete before kicking off it's own build. Is there any way to make sure this happens?
This is what I've tried so far:
LOCAL_ADDITIONAL_DEPENDENCIES := path/to/folder/for/android1.mk
Order of listing of these Android.m files (1 & 2)
Adding LOCAL_SHARED_LIBRARIES := a.so b.so ...
But, none of these have helped so far
######################################################################
# Android1.mk
######################################################################
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := a1.c a2.c
LOCAL_MODULE := lib_a
LOCAL_MODULE_TAGS := optional
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := b1.c b2.c
LOCAL_MODULE := lib_b
LOCAL_MODULE_TAGS := optional
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_SHARED_LIBRARY)
######################################################################
# Android2.mk
######################################################################
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := abc.c xyz.c
LOCAL_MODULE := lib_2
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_TAGS := optional
LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_ADDITIONAL_DEPENDENCIES := /path/to/folder/where/Android1.mk/resides
LOCAL_SHARED_LIBRARIES += \
lib_a \
lib_b
include $(BUILD_SHARED_LIBRARY)
The caveat is that abc.c/xyz.c doesn't make any calls in lib_a.so/lib_b.so/lib_z.so. But, I'm generating a script (in Android2.mk) and for that, require all the libraries (in Android1.mk) to be built prior

Found a way to achieve this:
# List out all the dependencies here
INTERMEDIATE_TARGET := \
lib_1
lib_2
generate.abc: $(INTERMEDIATE_TARGET)

Related

How to solve build error - Package modules may not define LOCAL_MODULE_SUFFIX

I am building an AOSP version for the first time and trying to put my application as a system app. So i made this android.mk file but during during build process, it is giving out error - Package modules may not define LOCAL_MODULE_SUFFIX. Can please someone help me out.
Alternatives to this method are also welcome, i just need to install my application as system app so that it gets more permissions.
My android.mk file is :-
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := CallRecorder_static
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_RESOURCE_DIR = $(LOCAL_PATH)/res
include $(BUILD_STATIC_JAVA_LIBRARY)
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_PACKAGE_NAME := CallRecorder
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_PRIVILEGED_MODULE := true
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)
LOCAL_STATIC_JAVA_LIBRARIES := libarity android-support-v4
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))

How to use shared library without header files in Android?

I have a shared lib (ex. libcrypto.so), but don't have header files.
Can I use this lib in other module?
I tried to use LOCAL_EXPORT_C_INCLUDES to export header files, but It doesn't work.
This is prebuilt module:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libcrypto
LOCAL_SRC_FILES := prebuilt/$(TARGET_ARCH_ABI)/libcrypto.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
And, this is module used libcrypto:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES += test.c # include "openssl/crypto.h"
LOCAL_C_INCLUDES += $(crypto_PATH)/include
LOCAL_SHARED_LIBRARIES += libcrypto
LOCAL_MODULE := libtest
LOCAL_MODULE_TAGS := optional
LOCAL_ARM_MODE := arm
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
This is libcrypto module (boringssl):
LOCAL_PATH := $(call my-dir)
# Target shared library
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libcrypto
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/src/include
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/crypto-sources.mk
LOCAL_SDK_VERSION := 9
LOCAL_CFLAGS += -fvisibility=hidden -DBORINGSSL_SHARED_LIBRARY -DBORINGSSL_IMPLEMENTATION -DOPENSSL_SMALL -Wno-unused-parameter
# sha256-armv4.S does not compile with clang.
LOCAL_CLANG_ASFLAGS_arm += -no-integrated-as
LOCAL_CLANG_ASFLAGS_arm64 += -march=armv8-a+crypto
include $(LOCAL_PATH)/crypto-sources.mk
include $(BUILD_SHARED_LIBRARY)
EDIT: Added boringssl module. I actually used #include "openssl/crypto.h" in test.c
Usually, you find crypto.h under include/openssl. So, in your case, either change the #include statement in test.c
#include "openssl/crypto.h"
Or (less recommended), edit
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/openssl

Adding a compiler flag to only one file in Android.mk

I have an Android.mk file that has a number of files for which LOCAL_CFLAGS get applied to them. I would like to apply a different flag to only one of the files out of the many. How can this be accomplished?
I searched the internet from the Android perspective, but didn't find a whole lot. Considering the following example I would like to apply flag TEST3 to file test3.c only. I looked at Per-file CPPFLAGS in Android.mk, but I couldn't find anything as far as how to use PRIVATE_CPPFLAGS to one file. Any ideas?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3
include $(BUILD_SHARED_LIBRARY)
The supported way to achieve your goal is to use a separate static library for C/CPP files that need different parameters. In this particular case, the fix would be as easy as
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test3
LOCAL_SRC_FILES := test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3 -DTEST3
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c
LOCAL_CFLAGS := -DTEST1_2_AND_3
LOCAL_WHOLE_STATIC_LIBRARIES := test3
include $(BUILD_SHARED_LIBRARY)
There is another approach, similar to one I forged a while ago
LOCAL_PATH := $(call my-dir)
TARGET-process-src-files-tags += $(call add-src-files-target-cflags, $(LOCAL_TEST3_SRC_FILES), $(LOCAL_TEST3_CFLAGS))
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3
LOCAL_TEST3_SRC_FILES := test3.c
LOCAL_TEST3_CFLAGS := -DTEST3
include $(BUILD_SHARED_LIBRARY)
If -Dtest3 would do, you can use another hack:
LOCAL_PATH := $(call my-dir)
get-src-file-target-cflags = $(LOCAL_SRC_FILES_TARGET_CFLAGS.$1) -D$(basename $1)_DEFINE
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test1.c test2.c test3.c
LOCAL_CFLAGS := -DTEST1_2_AND_3
include $(BUILD_SHARED_LIBRARY)
See more in How to dynamically get the current compiler target file name in Android.mk's LOCAL_CFLAGS?.

including header files android jni

I am trying to use pjsip on android.. after ./configure-android and make dep and make commands, static libraries were generated 13 of them.
I used the include folder which is copied inside jni folder. The content of android.mk in jni folder is as follows:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libpj-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpj-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjlib-util-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjlib-util-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../voiper/pjsip_lib/libpjmedia-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-audiodev-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-audiodev-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-codec-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-codec-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjmedia-videodev-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjmedia-videodev-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjnath-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjnath-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsdp-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsdp-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsip-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsip-simple-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-simple-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsip-ua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsip-ua-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsua2-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsua2-arm-unknown-linux-androideabi.a
LOCAL_MODULE := libpjsua-arm-unknown-linux-androideabi
LOCAL_SRC_FILES := ../pjsip_lib/libpjsua-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := dummy_pjsip_jni_module
LOCAL_SRC_FILES := dummy_pjsua.c
LOCAL_EXPORT_C_INCLUDES += ./include
LOCAL_C_INCLUDES += ./include
LOCAL_STATIC_LIBRARIES := libpj-arm-unknown-linux-androideabi libpjlib-util-arm-unknown-linux-androideabi libpjmedia-arm-unknown-linux-androideabi libpjmedia-audiodev-arm-unknown-linux-androideabi libpjmedia-codec-arm-unknown-linux-androideabi libpjmedia-videodev-arm-unknown-linux-androideabi libpjnath-arm-unknown-linux-androideabi libpjsdp-arm-unknown-linux-androideabi libpjsip-arm-unknown-linux-androideabi libpjsip-simple-arm-unknown-linux-androideabi libpjsip-ua-arm-unknown-linux-androideabi libpjsua2-arm-unknown-linux-androideabi libpjsua-arm-unknown-linux-androideabi
include $(BUILD_SHARED_LIBRARY)
I wrote a simple one line c file that only includes a header file inside include folder. Then i run ndk-build from the project directory and get no such file for the header file which is present inside the include folder. There is no application.mk.. What am i missing?
EDIT
the '.' represents the current directory.. "include" folder is inside jni folder
There are several issues here:
1) Each prebuilt static library should have its own module definition, i.e. your Android.mk should look like:
include $(CLEAR_VARS)
LOCAL_MODULE := libpj
LOCAL_SRC_FILES := libpj-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libpjlib-util
LOCAL_SRC_FILES := libpjlib-util-arm-unknown-linux-androideabi.a
include $(PREBUILT_STATIC_LIBRARY)
... etc
Note that the module name doesn't have to be exactly the same as the file path, which makes things a little clearer for the rest.
2) That '.' will refer, at build time, to the current directory where you invoke ndk-build, you need to use $(LOCAL_PATH)/include instead to refer to the right include path (assuming your Android.mk is under jni/ too). I.e.:
include $(CLEAR_VARS)
LOCAL_MODULE := dummy_pjsip_jni_module
LOCAL_SRC_FILES := dummy_pjsua.c
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := libpj libpjlib-util libpjmedia libpjmedia-audiodev \
libpjmedia-codec libpjmedia-videodev libpjnath \
libpjsdp libpjsip libpjsip-simple libpjsip-ua \
libpjsua2 libpjsua
include $(BUILD_SHARED_LIBRARY)

Simplifying an Android.mk file which build multiple executables

I am building some hardware tests for Android. I have an Android.mk file which builds these executables one-by-one, using a block of makefile code for each, as shown below:
##### shared #####
LOCAL_PATH := $(my-dir)
##### test_number_one #####
test_name := test_number_one
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(test_name)
LOCAL_SRC_FILES := tests/$(test_name)/$(test_name).c
include $(BUILD_EXECUTABLE)
##### test_number_two #####
test_name := test_number_two
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(test_name)
LOCAL_SRC_FILES := tests/$(test_name)/$(test_name).c
include $(BUILD_EXECUTABLE)
As you can see, the majority of the code is repeated for each test (between include $(CLEAR_VARS) and include $(CLEAR_VARS)). I would like to simplify this such that I have a list of test names and a section of makefile code which is 'called' for each one. I don't care if that code must be split into another file. Here's some python-esque pseudocode to demonstrate what I am going for:
##### shared #####
LOCAL_PATH := $(my-dir)
##### test_number_one #####
test_names := test_number_one test_numer_two
for each item in test_names:
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $(item)
LOCAL_SRC_FILES := tests/$(item)/$(item).c
include $(BUILD_EXECUTABLE)
Is this possible in Android.mk files? How can it be done?
You should be able to do something like
define my_add_executable
include $(CLEAR_VARS)
LOCAL_CFLAGS := $(commonCflags)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE_TAGS := optional eng
LOCAL_SHARED_LIBRARIES := some_library some_other_library
LOCAL_MODULE := $1
LOCAL_SRC_FILES := tests/$1/$1.c
include $(BUILD_EXECUTABLE)
endef
test_names := test_number_one test_numer_two
$(foreach item,$(test_names),$(eval $(call my_add_executable,$(item))))
We have similar construction in our project to include multiple prebuilt libraries.

Categories

Resources