NDK, LOCAL_EXPORT_C_INCLUDES not working as expected - android

Right now I am working on a native Android project and I want to use DevIL.
I don't want to put all the NDK code into one file, since DevIL needs multiple other libraries (libpng/libjpeg/...) and the Android.mk would end up being bloated.
I created a sub directory called Devil in my jni directory. I put all the code needed for DevIl (+ the libraries) in this directory. I also created an extra Android.mk file in this directory. In my "main" Android.mk file I added$(call import-module,DevIL) as well as: LOCAL_SHARED_LIBRARIES += libdevil. In the DevIL Android.mk I created an libdevil module and I used LOCAL_EXPORT_C_INCLUDES to link to the DevIL header files. When I put #include into my main.cpp file the ndk-build fails and complains "No such file or directory" in regards to the included header. If I don't put the #include into the code, the code compiles fine and all the shared libraries are created and put into the libs folder. What am I doing wrong?
My Main Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include cflags.mk
LOCAL_MODULE := arm
LOCAL_SRC_FILES := main.cpp
LOCAL_SHARED_LIBRARIES += libdevil
include $(BUILD_SHARED_LIBRARY)
$(call import-module,DevIL)
The Android.mk used for DevIl
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include cflags.mk
JPEG_SRC_PATH := Libjpeg/
DEVIL_SRC_PATH := DevIL/
#many more
#libjpeg
include $(CLEAR_VARS)
LOCAL_MODULE := libjpeg
LOCAL_C_INCLUDES := ${JPEG_SRC_PATH}
FILE_LIST := $(wildcard $(LOCAL_PATH)/JPEG_SRC_PATH/*.c)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
#many other libraries; basically the same as libjpeg
#libdevil
include $(CLEAR_VARS)
LOCAL_MODULE := libdevil
LOCAL_EXPORT_C_INCLUDES := \
${DEVIL_SRC_PATH}include \
${DEVIL_SRC_PATH}src-IL/include \
#many more
FILE_LIST := $(wildcard $(LOCAL_PATH)/DEVIL_SRC_PATHsrc-IL/src/*.c)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_STATIC_LIBRARIES := \
libjpeg \
#many more
LOCAL_LDLIBS += -lz
include $(BUILD_SHARED_LIBRARY)
The cflags.mk file
LOCAL_CFLAGS := -DANDROID_NDK
LOCAL_CFLAGS += -Werror
LOCAL_CFLAGS += -Wall
LOCAL_CFLAGS += -Wextra
LOCAL_CFLAGS += -Wno-strict-aliasing
LOCAL_CFLAGS += -Wno-unused-parameter
LOCAL_CFLAGS += -Wno-missing-field-initializers
LOCAL_CFLAGS += -Wno-multichar
LOCAL_CPPFLAGS := -Wno-type-limits
LOCAL_CPPFLAGS += -Wno-invalid-offsetof
LOCAL_CPPFLAGS += -std=c++11
LOCAL_CFLAGS += -std=c++11
LOCAL_CFLAGS += -fexceptions
LOCAL_CFLAGS += -Wno-error=deprecated-declarations
LOCAL_ARM_MODE := arm
Structure of the Directories
jni
|
+-- main.cpp
+-- Android.mk <- main Android
+-- Application.mk
+-- cflags.mk
|
+--DevIL
|
+-- Android.mk <- the Android.mk for DevIL
+-- cflags.mk
+--DevIL <-Directory containing DevIL source code
+--Libjpeg <-Directory containing code of specific DevIL dependency
+--...<-Directory containing code of specific DevIL dependency
Edit:
I noticed that I did not add my Application.mk, thus my Application.mk
Application.mk
APP_PLATFORM := android-19
APP_ABI := armeabi-v7a
APP_STL:=c++_static
APP_LDFLAGS := -Wl,--build-id
NDK_TOOLCHAIN_VERSION := 4.9
ROOT_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
NDK_MODULE_PATH := $(ROOT_DIR)

This does not answer the question, but if you are here from a search engine and happen to be having issues with LOCAL_EXPORT_C_INCLUDES on an AOSP module (not an NDK project!), Google's documentation at https://developer.android.com/ndk/guides/android_mk.html applies only to NDK projects.
For AOSP modules, the variable name is LOCAL_EXPORT_C_INCLUDE_DIRS, not LOCAL_EXPORT_C_INCLUDES.

Related

Android Ndk Error No rule to make target

I am try to build Android Cpp project using Ndk.
when i build app its only generate jni folder files
cannot generate jni sub folder files
i got this error
make: *** No rule to make target src/main/jni/src/main/jni/A/B/Helper.cpp', needed bybuild/intermediates/ndk/obj/local/armeabi/objs/demo/src/main/jni/A/B/Helper.o'. Stop.
TOP_LOCAL_PATH:=$(call my-dir)
LOCAL_PATH := $(TOP_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := demo
LOCAL_SRC_FILES := a.cpp b.cpp c.cpp d.cpp
LOCAL_SRC_FILES := $(LOCAL_PATH)/A/B/Helper.cpp
LOCAL_CFLAGS += -std=c++11 -frtti -fexceptions -fpermissive
LOCAL_LDLIBS += -llog -lGLESv2 -lEGL -landroid -lOpenSLES -lGLESv1_CM -lz
LOCAL_C_INCLUDES := $(LOCAL_PATH)/A/B
include $(BUILD_SHARED_LIBRARY)
The file names that are listed in LOCAL_SRC_FILES are relative to LOCAL_PATH. ALso, you can define this list on multiple lines, but by appending the list, not replacing it.
So, your Android.mk file should probably look like this:
TOP_LOCAL_PATH:=$(call my-dir)
LOCAL_PATH := $(TOP_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := demo
LOCAL_SRC_FILES := a.cpp b.cpp c.cpp d.cpp
LOCAL_SRC_FILES += A/B/Helper.cpp
LOCAL_CFLAGS += -std=c++11 -frtti -fexceptions -fpermissive
LOCAL_LDLIBS += -llog -lGLESv2 -lEGL -landroid -lOpenSLES -lGLESv1_CM -lz
LOCAL_C_INCLUDES := $(LOCAL_PATH)/A/B
include $(BUILD_SHARED_LIBRARY)
Note that the list LOCAL_C_INCLUDES should use full paths.

How to add static c-library (libsrtp) to Android-Project using NDK

so I'm relatively new to Android-NDK and trying to add an uncompiled c-library to android.
I've downloaded the library's source from here and followed these instructions to create a static library (.a-File) from the downloaded files using ndk-build.
So now I have a folder-structure that looks like this:
-srtp
--include (srtp.h, crypto.h)
--srtp (srtp.c...)
--obj
---local
----armeabi
-----libsrtp_static.a
In my Android-project I want to include srtp.h in a c-file inside my /jni/ folder. I've tried to just add the .a-file to the /jni folder but than it says "srtp.h no such file or direcotry". If I add the entire srtp-folder to the project and include the header with "srtp/include/srtp.h" it compiles but fails to link the source as I get the error "Undefined reference to srtp-function-call"
Here's my Android.mk (parts of it copied from Android.mk within the downloaded source):
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1 #name of my project
LOCAL_SRC_FILES := native.c #name of the c-source file
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH:= /home/dev/programing/srtp
common_SRC_FILES := \
srtp/srtp.c \
srtp/ekt.c \
crypto/cipher/cipher.c \
#...more files like that
common_CFLAGS := \
-DPOSIX -iquote$(LOCAL_PATH)/crypto/include \
-Werror \
-Wno-ignored-qualifiers \
-Wno-sign-compare \
-Wno-missing-field-initializers
common_C_INCLUDES = $(LOCAL_PATH)/include
# For the device
# =====================================================
# Device static library
include $(CLEAR_VARS)
ifneq ($(TARGET_ARCH),x86)
LOCAL_NDK_VERSION := 5
LOCAL_SDK_VERSION := 9
endif
LOCAL_SRC_FILES := libsrtp_static.a
LOCAL_CFLAGS += $(common_CFLAGS)
LOCAL_C_INCLUDES += /home/dev/programing/srtp/include
LOCAL_MODULE:= libsrtp_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
Any help is greatly appreciated! Thank you very much.
You need to add the reference to libsrtp_static from your lib (ndk1) declaration :
LOCAL_STATIC_LIBRARIES := libsrtp_static
Also, you don't need to copy all the strp sources to your project, only add this to your static prebuilt library definition
LOCAL_EXPORT_C_INCLUDES += /home/dev/programing/srtp/include
This path will then be automatically added to the LOCAL_C_INCLUDES of your library that is using the library.
Are you building libsrtp or just using a prebuilt static library ? If you're using a prebuilt (lib*.a), replace BUILD_STATIC_LIBRARY with PREBUILT_STATIC_LIBRARY and set only the .a as SRC_FILE:
In summary, once libstrp_static.a is built, this should work:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1 #name of my project
LOCAL_SRC_FILES := native.c #name of the c-source file
LOCAL_STATIC_LIBRARIES := libsrtp_static
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := /home/dev/programing/srtp/libsrtp_static.a #check path to libsrtp_static.a
LOCAL_EXPORT_C_INCLUDES += /home/dev/programing/srtp/include
LOCAL_MODULE:= libsrtp_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)

NativeActivity using C++

I'm trying to only use c++ to porting all my apps on Android devices from IOS and from ANDROID with JAVA EGL.
One thing I just met is "fatal error: android_native_app_glue.h: No such file or directory" so I'm going over my make file , 'Android.mk' below
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_DEFAULT_CPP_EXTENSION := cpp
LOCAL_MODULE := StarEngine
LOCAL_SRC_FILES := \
main.cpp \
StarEngine.cpp \
../../../StarEngine/StarShader.cpp \
../../../StarEngine/StarTexture.cpp \
../../../StarEngine/StarFBO.cpp\
../../../StarEngine/StarTimer.cpp\
../../../StarEngine/StarMath/Matrix.cpp\
../../../StarEngine/StarMath/Random.cpp\
../../../StarEngine/StarMath/Transform.cpp\
../../../StarEngine/StarMath/Vector.cpp\
../../../StarEngine/StarMath/neonmath/neon_matrix_impl.cpp\
../../../StarEngine/StarMath/vfpmath/matrix_impl.cpp\
../../../StarEngine/StarMath/vfpmath/utility_impl.cpp\
#../../../StarEngine/StarSound/StarSound.cpp
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
LOCAL_CFLAGS := -D_ARM_ARCH_7=1
LOCAL_CPPFLAGS := -D_ARM_ARCH_7=1
else
endif
LOCAL_CFLAGS := -DCONFIG_EMBEDDED -DUSE_IND_THREAD -marm -mfpu=neon -mfloat-abi=softfp
APP_STL := stlport_static
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -ldl -lGLESv2 -landroid -lEGL -lGLESv1_CM
LOCAL_STATIC_LIBRARIES := android_native_app_glue cpufeatures
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cpufeatures,android/native_app_glue)
Answer :
When you use more than two static libraries you should put import-module more than twice like this
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
$(call import-module,cpufeatures)
According to the reference in NDK folder :
import-module
A function that allows you to find and include the Android.mk
of another module by name. A typical example is:
$(call import-module,<name>)
And this will look for the module tagged <name> in the list of
directories referenced by your NDK_MODULE_PATH environment
variable, and include its Android.mk automatically for you.

openssl as shared library in Android Native Code

I have just compiled the OpenSSL for Android. I have the libcrypto.so and libssl.so shared libraries. I created a sample Android Application called TrialApp. The idea is to use some native functions that would call the libssl and libcrypto shared libraries. Therefore, under my jni directory,I have a TrialApp.cpp which includes a simple SHA1 example.Here is the tree structure of my NDK Application directory on Eclipse:
TrialApp
|
|-->Activity.java
|
|-->TrialApp.java(which includes System.LoadLibrary calls)
|
|-->jni
|-->TrialApp.cpp
|
|-->Android.mk
|
|-->includes
| |
| |-->openssl (dir containing *.h files)
|
|-->precompiled
|-->libssl.so
|-->libcrypto.so
Here is the Android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := TrialApp
LOCAL_SRC_FILES := TrialApp.cpp
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/includes/openssl
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so
LOCAL_STATIC_LIBRARIES := sslx cryptox
include $(BUILD_SHARED_LIBRARY)
But then the openssl headers in TrialApp,.cpp cannot be found by the compiler.
The error I get:
fatal error: openssl/evp.h: No such file or directory
Can someone tell me how to resolve it?
Thanks.
Include dirs are set up in compiler flag -I: so, set up LOCAL_CFLAGS variable with appropriate key and header location like this: LOCAL_CFLAGS += $(cf_includes) where cf_includes is defined like cf_includes:= includes/openssl + cf_includes := $(addprefix -Ijni/,$(cf_includes))
In other words you have to defile LOCAL_CFLAGS like this:LOCAL_CFLAGS += -Ijni/includes/openssl
Try to replace your android.mk with
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
c_includes := $(LOCAL_PATH)
cf_includes:= includes/openssl
cf_includes := $(addprefix -Ijni/,$(cf_includes))
export_c_includes := $(c_includes)
LOCAL_MODULE := TrialApp
LOCAL_SRC_FILES := TrialApp.cpp
LOCAL_CFLAGS += $(cf_includes)
LOCAL_EXPORT_C_INCLUDES := $(export_c_includes)
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libssl.so
LOCAL_LDLIBS += $(LOCAL_PATH)/precompiled/libcrypto.so
LOCAL_STATIC_LIBRARIES := sslx cryptox
include $(BUILD_SHARED_LIBRARY)
Hope it helps

Android NDK: Including boost c++ library

I am trying to use a boost library inside my android application, using the NDK. I have found a couple of success stories here and here, but I can't say the same about me. I am specifically trying to use the library in this link, as well as the boost thread library. In the code below, I am only trying to include the thread library, not the math library. The process I used to build the boost libraries is pretty much the same as the first link I attached.
So far, it seems I have successfully built the boost libraries, but when I run ndk-build, I get the following error:
Prebuilt : libboost_thread.a <= <NDK>/sources/
cp: omitting directory `path/to/ndk/sources/boost'
make: *** [obj/local/armeabi/libboost_thread.a] Error 1
Obviously the cp: omitting directory... is not exactly an error. But the only thing I'm getting other than that is the next line, which doesn't really mean anything. Error 1
Here's my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := boost_thread
LOCAL_LDLIBS := lboost_system-gcc-md lboost_thread-gcc-md -lgnustl_static
LOCAL_LDLIBS += lboost_system-gcc-md lboost_thread-gcc-md \
-L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/libs/armeabi \
-lgnustl_static
LOCAL_SRC_FILES := #cpp_sources
LOCAL_MODULE := com_example_ndkFile_CppMethods
include $(BUILD_SHARED_LIBRARY)
$(call import-module,boost)
And there's also an Android.mk file in path/to/ndk/sources/boost/:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_thread
LOCAL_SRC_FILES:= android/lib/libboost_thread.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
And my humble Application.mk file:
APP_ABI := armeabi armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS = -fexceptions
I built the boost libraries using bjam. All of the libboost_###.a files are in the sources/boost/android/lib folder.
What is the error I'm getting?
I built the boost libraries using Boost-for-Android. Then I have in my boost/include/lib directory the android makefile boost.mk
LOCAL_PATH := $(call my-dir)
# boost_date_time
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_date_time
LOCAL_SRC_FILES := libboost_date_time-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# 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_thread
LOCAL_SRC_FILES := libboost_thread-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_program_options
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_program_options
LOCAL_SRC_FILES := libboost_program_options-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
# boost_chrono
#
include $(CLEAR_VARS)
LOCAL_MODULE := boost_chrono
LOCAL_SRC_FILES := libboost_chrono-gcc-mt-1_53.a
include $(PREBUILT_STATIC_LIBRARY)
and my module where i use some of the boost libraries looks like this
LOCAL_PATH := $(call my-dir)
# SignalServer, executable
#
include $(CLEAR_VARS)
LOCAL_CFLAGS := -DTIXML_USE_TICPP
#LOCAL_CFLAGS += -DDEBUG
LOCAL_STATIC_LIBRARIES := boost_thread \
boost_system \
boost_filesystem \
boost_program_options \
boost_chrono \
LOCAL_STATIC_LIBRARIES += ticpp \
tia \
tobicore \
tobiid \
tid \
gdf
LOCAL_MODULE := signalserver
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/extern/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../boost/include/boost-1_53
LOCAL_SRC_FILES := #cpp source
include $(BUILD_EXECUTABLE)
in addition I have an Android.mk where all subdir makefiles are listed
TOP_PATH := $(call my-dir)
include $(TOP_PATH)/boost/lib/boost.mk
include $(TOP_PATH)/signalserver/signalserver.mk
.
.
and my Application.mk:
APP_PLATFORM := android-14
APP_ABI := armeabi-v7a
#APP_OPTIM := debug
#NDK_DEBUG := 1
NDK_TOOLCHAIN_VERSION := 4.6
APP_STL := gnustl_static
APP_CPPFLAGS := -fexceptions -frtti
Here: http://silverglint.com/boost-for-android/ you can find a simple script that lets you build a modern version of boost for android, or simply download prebuilt boost binaries.
Also included is a sample test app that shows you how to include/link the boost headers/binaries

Categories

Resources