How to include Android.mk in another makefile - makefile

I have a problem including another Android.mk and build the dependent shared library.
Makefile:
LOCAL_PATH := $(call my-dir)
MY_CORE_PATH := $(abspath $(LOCAL_PATH)/../..)
include $(CLEAR_VARS)
LOCAL_MODULE := Phone
LOCAL_SRC_FILES := phone.cpp
LOCAL_SHARED_LIBRARIES := libCore
include $(BUILD_SHARED_LIBRARY)
include $(MY_CORE_PATH)/Android.mk
When I compile this I get an error,
make: *** No rule to make target 'libCore.so' needed by 'libPhone.so'. Stop.
The libCore.so however builds without any issues but this makefile is not able to refer that correctly. Please provide any suggestions on how to resolve this.
NDK and Android version: android-ndk-r6, API level 9 building for Android ICS.
I am currently able to resolve by making the following changes.
# Modified Android.mk
LOCAL_PATH := $(call my-dir)
MY_CORE_PATH := $(abspath $(LOCAL_PATH)/../..)
# libCore
include $(CLEAR_VARS)
LOCAL_MODULE := Core
include $(MY_CORE_PATH)/Android.mk
include $(CLEAR_VARS)
LOCAL_MODULE := Phone
LOCAL_SRC_FILES := phone.cpp
LOCAL_SRC_FILES += libCore
include $(BUILD_SHARED_LIBRARY)

I found the reason for my compile error. It is because the LOCAL_MODULE name is not correctly provided in the other makefile. Below are the changes done,
[1] In the Android.mk that was building libCore.so, module name was mentioned as,
LOCAL_MODULE := Core
instead of
LOCAL_MODULE := libCore
[2] The last two statements are interchanged; Makefile is first included and then the library is built.
My understanding was that 'lib' is optional in the module name. I didn't doubt this because it was building fine within NDK, problem seen when it is built as part of Android source tree.

Related

Android library linking and LOCAL_SRC_FILES points to a missing file

I’m trying to compile my Cocos2d-x project with OpenSSL to Android. I can run the project properly on Visual Studio Community 2013, but can’t compile it on the command line with cocos compile -p android --android-studio.
I installed OpenSSL to path project\cocos2d\external\OpenSSL-Win32 and added the OpenSSL include path to the Android.mk file:
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../proj.win32 \
$(LOCAL_PATH)/../../../cocos2d/external/OpenSSL-Win32/include
I followed Undefined reference to libssl function with Android NDK, but it didn't really help. I don't have shared libraries in my OpenSSL folder, only static ones. The best I can come up with for now is this definition:
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../../cocos2d/external/OpenSSL-Win32/lib/MinGW/libcrypto-1_1.a
include $(PREBUILT_STATIC_LIBRARY)
This gave me the following error:
Android NDK: ERROR:jni/Android.mk:crypto: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that jni/jni/../../../cocos2d/external/OpenSSL-Win32/lib/MinGW/libcrypto-1_1.a exists or that its path is correct
The file libcrypto-1_1.a is in that folder.
Edit
I downloaded prebuilt OpenSSL libraries (shared libs included) for Android from here: https://github.com/r4sas/OpenSSL-1.1-Android-Prebuilt.
This package contains an Android.mk file that has definitions for shared libraries:
include $(CLEAR_VARS)
LOCAL_MODULE := opencrypto
LOCAL_SRC_FILES := libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := openssl
LOCAL_SRC_FILES := libssl.so
include $(PREBUILT_SHARED_LIBRARY)
I added these definitions to the Android.mk file in folder cocos2dx-project\proj.android-studio\app\jni.
It also contains libcrypto.so and libssl.so files. I copied these files to cocos2dx-project\proj.android-studio\app\jni and tried to compile the project, but got the following errors:
Android NDK: Trying to define local module 'openssl' in jni/Android.mk.
Android NDK: But this module was already defined by jni/Android.mk.
Edit 2
I think I have made some progress.
My Android.mk looks like this now:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := crypto
LOCAL_SRC_FILES := libcrypto.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := openssl
LOCAL_SRC_FILES := libssl.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos)
$(call import-add-path,$(LOCAL_PATH)/../../../cocos2d/cocos/audio/include)
LOCAL_MODULE := MyLib_shared
LOCAL_MODULE_FILENAME := libMyLib
LOCAL_SRC_FILES := hellocpp/main.cpp \
...
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../proj.win32 \
$(LOCAL_PATH)/../../../cocos2d/external/openssl/include
# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static
# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
Those shared libraries are now build properly, but I get the undefined reference error:
[armeabi] Install : libcrypto.so => libs/armeabi/libcrypto.so
[armeabi] Install : libssl.so => libs/armeabi/libssl.so
[armeabi] SharedLibrary : libMyLib.so
jni/../../../proj.win32/EncryptionHelper.cpp:61: error: undefined reference to 'EVP_CIPHER_CTX_new'
Instead of trying to make this work using a shared library, I used a static one.
Added this to Android.mk:
include $(CLEAR_VARS)
LOCAL_MODULE := crypto_static
LOCAL_SRC_FILES := libcrypto.a
include $(PREBUILT_STATIC_LIBRARY)
...
LOCAL_STATIC_LIBRARIES := cocos2dx_static \ crypto_static
It compiles properly now.
Thank you jww for all the helpful comments and for pointing me in the right direction!

Android NDK builds well, gradle cant find header

I have an android problem. I am using ndk with makefiles and android studio with gradle.
My app should use boost and a premade library too, called "kodo".
I made makefiles like this:
Android.mk
LOCAL_PATH := $(call my-dir)
# build jni
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := **/*.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := all
APP_STL := stlport_static
And I have some code, that uses these:
#include <kodo/object/file_encoder.hpp>
#include <kodo/rlnc/full_rlnc_codes.hpp>
#include <boost/format.hpp>
#include <boost/filesystem.hpp>
The first words are red, stating cannot find 'kodo' and cannot find 'boost'.
NDK-build runs well (seemingly) having no errors.
Still the build fails, when trying to be put together in an app.
If you could help, I would be so happy.
Thanks,
Krisz.

Android NDK: Include Boost library

I am trying to build a Android NDK project including two libraries:
OpenCV and Boost
I think that including openCV worked fine, but I have problems with boost. To build boost I followed the instructions here: https://github.com/MysticTreeGames/Boost-for-Android
I used Boost 1.53 and Android NDK r8e to build boost.
I set up my make files like this:
Application.mk
APP_PLATFORM := android-8
APP_ABI := armeabi-v7a
APP_OPTIM := debug
NDK_DEBUG := 1
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
Android.mk
LOCAL_PATH := $(call my-dir)
include ./jni/opencv/sdk/native/jni/OpenCV.mk
include ./jni/boost/lib/boost.mk
include ./jni/usit/usit.mk
boost.mk
LOCAL_PATH := $(call my-dir)
# boost_filesystem
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_filesystem
LOCAL_SRC_FILES := libboost_filesystem-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_thread
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_regex
LOCAL_SRC_FILES := libboost_regex-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_system
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_system
LOCAL_SRC_FILES := libboost_system-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_system
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_date_time
LOCAL_SRC_FILES := libboost_date_time-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
To set this up I followed this example: How to use the boost library (including shared_ptr) with the Android NDK and STLport
But I am getting this error:
/home/tassilo/android-ndks/android-ndk-r8e/build/core/build-executable.mk:23: *** Android NDK: Missing LOCAL_MODULE before including BUILD_EXECUTABLE in jni/Android.mk . Stop.
when trying to run ndk-build.
All my sources are available here: https://github.com/4ndro1d/irisrec.git
My target is to compile the file wahet.cpp without errors.

Can GNU make have targets that depend on the completion of targets from other makefiles?

I have several directories representing subparts of a project, each with its own Makefile.
I want to create a master Makefile with targets for each of those subparts, each target satisfying the following:
depend on a certain target from that subproject's Makefile.
This is the tricky part.
copy some resulting library/executable build by the subproject into a central directory (kind of like "make install"-ing it).
This I can already achieve using simple commands.
I could only find information about the include directive of GNU make, but that doesn't help me much as it seems not to encapsulate the rules (and execution) of the included makefile in its own directory, but instead just #includes them C-style (rather that thinking of them as packages with separate scopes).
INSTALLDIR := build
SRCDIR := src
TARGETS := projA projB
.PHONY: $(TARGETS)
TARGETS_PATH := $(addprefix $(SRCDIR)/, $(TARGETS))
MAKEFILES := $(addsuffix /osx.mak, $(TARGETS_PATH))
# include them somehow?
For such a setup as defined above, I now want each of $(TARGETS) to depend on the release target of its corresponding Makefile (something like projA: $(SRCDIR)/projA/osx.mak # release for projA, in my own language meaning that target projA depends on the successful execution of the release target in that specific Makefile).
Is there any way to achieve this?
You can suggest other tools apart from GNU make, but the subproject makefiles are already written as makefiles.
Have a look at recursive make.
You could do something like,
SRCDIR := src
TARGETS := projA projB
.PHONY: $(TARGETS)
$(TARGETS):
cd $(SRCDIR)/$#; $(MAKE) release

Port Boost to Android

Has somebody ported and used Boost on Android?
I've found the tool which builds boost for android (https://github.com/MysticTreeGames/Boost-for-Android), the build is successful, and i've got static boost libs.
But when i'm tring to use it in simple android app:
#include <jni.h>
#include "boost/thread.hpp"
void f()
{
};
i've got a lot of compilation errors: redefinitions, undeclared etc. Seems it concerns NDK std headers.
My Android.mk looks like:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
TARGET_PLATFORM := android-8
LOCAL_MODULE := Boost
LOCAL_CFLAGS := -DMYSTIC -I$(LOCAL_PATH)/boost/include/
LOCAL_LDLIBS := -L$(LOCAL_PATH)/external/boost/lib/
LOCAL_CPPFLAGS := -fexceptions
LOCAL_CPPFLAGS += -frtti
LOCAL_CPPFLAGS += -DBOOST_THREAD_LINUX
LOCAL_CPPFLAGS += -DBOOST_HAS_PTHREADS
LOCAL_CPPFLAGS += -D__arm__
LOCAL_CPPFLAGS += -D_REENTRANT
LOCAL_CPPFLAGS += -D_GLIBCXX__PTHREADS
LOCAL_CPPFLAGS += -DBOOST_HAS_GETTIMEOFDAY
LOCAL_SRC_FILES := main.cpp
include $(BUILD_SHARED_LIBRARY)
Also I tried to build with Crystax_NDK_r4 and Android_NDK_r5b but it hasn't resolved the problem.
Any ideas?
I've solved the problem. I specified the incorrect path to NDK. Script patches CrystaX NDK too. So now it works!
I just found a easy way to build boost under android NDK, which don't need patching the boost.
I don't use Android.mk to build boost, instead, I use the standalone-toolchain to build, just link CodeSourcery's toolchain.
Prepare the NDK toolchain first:
Install the NDK toolchain as a standalone toolchain. See $NDK/docs/STANDALONE-TOOLCHAIN.html
Add the bin path of cross-toolchain to your PATH
Build boost.Build tool, in Boost prj:
./bootstrap.sh
echo "using gcc : android : arm-linux-androideabi-g++ ;" > $HOME/user-config.jam
Build example
./b2 --prefix=$HOME/mybuild --with-thread --with-system toolset=gcc-android threading=multi link=static install
I hope these can help you.
You can download a collection of scripts that will download and build some popular c/c++ open source libraries for android and ios including boost at this location.
https://github.com/mevansam/cmoss

Resources