Depending on my first question, I tried to include the fanotify.h header in my application. The application is based on fsmon (a small application to use the fanotify syscall), I changed some code lines for my purpose and created an Android.mk makefile:
APP_PLATFORM := android-23
TARGET_PLATFORM := android-23
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Enable PIE manually. Will get reset on $(CLEAR_VARS). This
# is what enabling PIE translates to behind the scenes.
LOCAL_CFLAGS += -fPIE -DHAVE_FANOTIFY=1 -DHAVE_SYS_FANOTIFY=0
LOCAL_LDFLAGS += -fPIE -pie
# give module name
LOCAL_MODULE := fsmon
# include fanotify by api 23:
LOCAL_C_INCLUDES := /home/fabian/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm/usr/include
# include fanotify by sysroot ->
# LOCAL_C_INCLUDES := /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/
# list your C files to compile
LOCAL_SRC_FILES := inotify.c fanotify.c util.c main.c
# this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)
I need to include the linux/inotify.h and the linux/fanotify.h headers.
On executing ndk-build, only the arm64-v8a, mips64 and x86_64 executable files (in libs/xxx) get created cause of following error messages:
fabian#fabian-ubuntu:~/kernel_android_goldfish/fsmon/fsmon/jni$ ndk-build
[arm64-v8a] Compile : fsmon <= inotify.c
[arm64-v8a] Compile : fsmon <= fanotify.c
[arm64-v8a] Compile : fsmon <= util.c
[arm64-v8a] Compile : fsmon <= main.c
[arm64-v8a] Executable : fsmon
[arm64-v8a] Install : fsmon => libs/arm64-v8a/fsmon
[x86_64] Compile : fsmon <= inotify.c
[x86_64] Compile : fsmon <= fanotify.c
[x86_64] Compile : fsmon <= util.c
[x86_64] Compile : fsmon <= main.c
[x86_64] Executable : fsmon
[x86_64] Install : fsmon => libs/x86_64/fsmon
[mips64] Compile : fsmon <= inotify.c
[mips64] Compile : fsmon <= fanotify.c
[mips64] Compile : fsmon <= util.c
[mips64] Compile : fsmon <= main.c
[mips64] Executable : fsmon
[mips64] Install : fsmon => libs/mips64/fsmon
[armeabi-v7a] Compile thumb : fsmon <= inotify.c
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:49:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/signal.h:21:
In file included from /home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:82:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:92:21: error: use of undeclared identifier
'__BITS_PER_LONG'
unsigned long sig[_NSIG_WORDS];
^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:25:38: note: expanded from macro '_NSIG_WORDS'
#define _NSIG_WORDS (_KERNEL__NSIG / _NSIG_BPW)
^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:24:19: note: expanded from macro '_NSIG_BPW'
#define _NSIG_BPW __BITS_PER_LONG
^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:94:3: error: typedef redefinition with different
types ('struct (anonymous struct at /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:91:9)' vs
'unsigned long')
} sigset_t;
^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:20:23: note: previous definition is here
typedef unsigned long sigset_t;
^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:84:8: error: redefinition of 'sigaction'
struct sigaction {
^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:101:8: note: previous definition is here
struct sigaction {
^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:49:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/signal.h:21:
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:97:16: error: redefinition of
'sigaltstack'
typedef struct sigaltstack {
^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:111:16: note: previous definition is here
typedef struct sigaltstack {
^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:49:
In file included from /home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/linux/signal.h:21:
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:101:3: error: typedef redefinition with
different types ('struct (anonymous struct at
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:97:16)' vs 'struct sigaltstack')
} stack_t;
^
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/asm-generic/signal.h:116:3: note: previous definition is here
} stack_t;
^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:71:9: warning: 'NSIG' macro redefined [-Wmacro-redefined]
#define NSIG _NSIG
^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:19:9: note: previous definition is here
#define NSIG 32
^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:79:9: warning: 'SIGRTMIN' macro redefined [-Wmacro-redefined]
#define SIGRTMIN (__libc_current_sigrtmin())
^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:58:9: note: previous definition is here
#define SIGRTMIN 32
^
In file included from /home/fabian/kernel_android_goldfish/fsmon/fsmon/jni/inotify.c:9:
/home/fabian/Android/Sdk/ndk-bundle/sysroot/usr/include/signal.h:80:9: warning: 'SIGRTMAX' macro redefined [-Wmacro-redefined]
#define SIGRTMAX (__libc_current_sigrtmax())
^
/home/fabian/Android/Sdk/ndk-bundle/platforms/android-9/arch-arm/usr/include/asm/signal.h:59:9: note: previous definition is here
#define SIGRTMAX _NSIG
^
5 errors generated.
make: *** [/home/fabian/kernel_android_goldfish/fsmon/fsmon/obj/local/armeabi-v7a/objs/fsmon/inotify.o] Error 1
Cause of inotify.c including the signal.h header which re-includes the linux/signal.h and this in turn the platforms/android-9/arch-arm/usr/include/asm/signal.h , where the error appears. (suddenly from android-9).
I can't figure out where the problem is.. I tried to include the include folder from sysroot - but similar errors appear.
Source file:
inotify.c
fanotify.c
You shouldn't manually point to the NDK headers in LOCAL_C_INCLUDES. This should be added automatically, pointing to the right version. However, nothing actually uses the variables APP_PLATFORM or TARGET_PLATFORM here.
Instead, add APP_PLATFORM := android-23 in the file jni/Application.mk. That should make it build using the right platform headers, for all architectures.
In addition to #mstorsjo's answer, you can use Unified Headers in NDK r14 and newer. These are a new form of the headers that will always be up to date rather than having a different set of headers for each API level.
The advantage of this over increasing your APP_PLATFORM is that your APP_PLAFORM cannot be higher than your minSdkVersion (see our common problems doc). Since fanotify was introduced in a fairly old version of the kernel (2.6.36 for fanotify_init), you should still be able to call it with syscall(__NR_fanotify_init) even though the function doesn't exist in libc in the old version. Still, ENOSYS is always a possibility.
By default in r14 you still get the old form of the headers. The new "unified headers" have the headers you're looking for. If you want to try unified headers, set APP_UNIFIED_HEADERS := true in your Application.mk (settings for other build systems can be found in the link above).
In r15 (first beta due out soon), the default has changed to the new headers, and the option for disabling them has changed (see the same doc in r15).
Related
i have problem when replace fixed libpng. i used cocos2d1.0.1-x-0.13.0-beta/ndkr8
Compile++ thumb : cocos2dx_static <= CCFileUtils.cpp
Compile++ thumb : cocos2dx_static <= CCGL.cpp
Compile++ thumb : cocos2dx_static <= CCImage.cpp
C:/Users/trach/Pictures/cocos2d-1.0.1-x-0.13.0-beta/cocos2dx/platform/CCImage.cpp: In member function 'bool cocos2d::CCImage::_initWithPngData(void, int)':
C:/Users/trach/Pictures/cocos2d-1.0.1-x-0.13.0-beta/cocos2dx/platform/CCImage.cpp:257:33: error: invalid use of incomplete type 'png_info {aka struct png_info_def}'
C:/Users/trach/Pictures/cocos2d-1.0.1-x-0.13.0-beta/cocos2dx/platform/third_party/android/prebuilt/libpng/include/png.h:594:16: error: forward declaration of 'png_info {aka struct png_info_def}'
make: ** [/cygdrive/c/Users/trach/Pictures/android-ndk-r8e/build/core/build-binary.mk:273: obj/local/armeabi/objs/cocos2dx_static/platform/CCImage.o] Error 1
make: Leaving directory '/cygdrive/c/Users/trach/Pictures/cocos2d-1.0.1-x-0.13.0-beta/show_entry'
cp: cannot create regular file '/cygdrive/c/Users/trach/Pictures/cocos2d-1.0.1-x-0.13.0-beta/show_entry/jni/../libs/armeabi': No such file or directory
libpng-1.5 and later do not allow direct access to the members of png_ptr, so you have to replace things like
png_info->width
png_ptr->width
with things like
png_get_image_width(png_ptr,png_info)
in your application, or downgrade libpng to the latest 1.2.x version.
When I build my C/C++ library using ndk-build command from the command line, it works.
[armeabi] Prebuilt : libVidyoClientApp.so <= jni/lib/
[armeabi] Install : libVidyoClientApp.so => libs/armeabi/libVidyoClientApp.so
[armeabi] Compile thumb : vidyoguestapi <= NCR.JNI.VidyoExports.c
[armeabi] Compile++ thumb: vidyoguestapi <= Ncr.Jni.Wrapper.cpp
In file included from m:/src/projects/java/VideoPlatform/app/src/main/jni/Ncr.Jni.Wrapper.cpp:6:0:
m:/src/projects/java/VideoPlatform/app/src/main/jni/include/Ncr.Jni.Wrapper.h:13:1: warning: 'typedef' was ignored in th
is declaration [enabled by default]
};
^
[armeabi] Compile++ thumb: vidyoguestapi <= NCR.Vidyo.SDK.cpp
In file included from m:/src/projects/java/VideoPlatform/app/src/main/jni/NCR.Vidyo.SDK.cpp:7:0:
m:/src/projects/java/VideoPlatform/app/src/main/jni/include/NCR.Jni.Wrapper.h:13:1: warning: 'typedef' was ignored in th
is declaration [enabled by default]
};
^
[armeabi] StaticLibrary : libstdc++.a
[armeabi] SharedLibrary : libvidyoguestapi.so
[armeabi] Install : libvidyoguestapi.so => libs/armeabi/libvidyoguestapi.so
But when I try to build my project in Android studio I get a compiler error:
M:\src\projects\java\VideoPlatform\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/vidyoguestapi/M_\src\projects\java\VideoPlatform\app\src\main\jni\NCR.JNI.VidyoExports.o: In function `Java_com_ncr_mobilevideo_videosdk_VidyoGuestClient_sdkLoginGuest':
M:\src\projects\java\VideoPlatform\app\src\main\jni\NCR.JNI.VidyoExports.c
Error:(50) undefined reference to `VidyoClientInitialize'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [M:\src\projects\java\VideoPlatform\app\build\intermediates\ndk\debug\obj/local/arm64-v8a/libvidyoguestapi.so] Error 1
What is different between commandline ndk-build and Android Studio?
FYI: I remove the line that references VidyoClientInitialize, everything builds in both the commandline and Android studio. So it seems like something environment, but I'm not sure what to look at
Right now, Android Studio creates a new Android.mk on-the-fly to compile your C/C++ sources, ignoring all your dependencies on other prebuilt libraries since he can't handle them.
A better NDK support from AS/gradle is supposed to be out really soon, but in the meantime you can deactivate it and let it integrate your native libs from libs/(armeabi,armeabi-v7a,x86,...) by setting this inside build.gradle:
android {
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set libs as .so's location instead of jniLibs
jni.srcDirs = [] //disable automatic ndk-build call with auto-generated Android.mk
}
}
I have been following this tutorial http://developer.samsung.com/android/technical-docs/Porting-and-using-LAME-MP3-on-Android-with-JNI, however I dont seem to get it to compile when it comes to Compilation with NDK section. The following is the error that I get
Android NDK: WARNING: APP_PLATFORM android-17 is larger than android:minSdkVersion 7 in ./AndroidManifest.xml
[armeabi] Compile thumb : mp3lame <= bitstream.c
jni/./libmp3lame/bitstream.c:33:18: fatal error: lame.h: No such file or directory
compilation terminated.
make.exe: * [obj/local/armeabi/objs/mp3lame/./libmp3lame/bitstream.o] Error 1
I have added
LOCAL_C_INCLUDES += jni/include
to Android.mk, so it can find the ".h" needed.
I'm using android-ndk-r9b and cocos2d-x-2.1.4 under MacOs Mavericks. I was able to create the android application for cocos2d-x, but when I tried to compile the C++ code using ./build_native.sh script, the compiler get me some warnings and at the end failed.
These warnings are:
Android NDK: WARNING: APP_PLATFORM android-18 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
Android NDK: WARNING:/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries
[armeabi] Compile thumb : cocos2dx_static <= quaternion.c
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/kazmath/src/quaternion.c: In function 'kmQuaternionAssign':
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/kazmath/src/quaternion.c:478:5: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
[armeabi] Compile thumb : cocos2dx_static <= vec4.c
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/kazmath/src/vec4.c: In function 'kmVec4Assign':
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/kazmath/src/vec4.c:150:5: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
[armeabi] Compile++ thumb: cocos2dx_static <= CCCommon.cpp
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLog(char const*, ...)':
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/platform/android/CCCommon.cpp:44:72: error: format not a string literal and no format arguments [-Werror=format-security]
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLuaLog(char const*)':
/Developer/cocos2d-x-2.1.4/samplecocos2dxandroid/proj.android/../../cocos2dx/platform/android/CCCommon.cpp:54:77: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus: some warnings being treated as errors
I'm wondering if someone has encounter similar errors, how how to revolve it?
Thanks!
Same problem here (Cocos2DX 2.1.1)
http://www.cocos2d-x.org/forums/6/topics/32437?r=39742#message-39742
You can shut down the compiler error:
in Application.mk:
APP_CFLAGS += -Wno-error=format-security
or better, solve the problem of string format, in 4 points of cocos code (as you can see in the link above):
1 - CCCommon.cpp - __android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", buf); -> __android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf);
2 - SimpleAudioEngine.cpp - LOGD(deviceModel); -> LOGD("%s",deviceModel);
3 - OpenSLEngine.cpp - LOGD(errorInfo); -> LOGD("%s",errorInfo);
4 - SimpleAudioEngineOpenSL.cpp - LOGD(errorInfo); -> LOGD("%s",errorInfo);
I am using open-ssl source given at https://github.com/eighthave/openssl-android
to build a library which can be used in android project.
As per instructions given at README.txt, I am able to compile it for the the Android platform version 2.2 (level -8)
But my app requires it to be 2.1 (level -7) compatible.
I tried following options with the default.properties file ( https://github.com/eighthave/openssl-android/blob/master/default.properties )
1) set target=android-7
2) set target=android-5
But when I compile it using command ndk-build, it gives following error
Compile thumb : crypto <= dsa_vrf.c
Compile thumb : crypto <= dso_dl.c
Compile thumb : crypto <= dso_dlfcn.c
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c: In function 'dlfcn_pathbyaddr':
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: 'Dl_info' undeclared (first use in this function)
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: (Each undeclared identifier is reported only once
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: for each function it appears in.)
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:445: error: expected ';' before 'dli'
/Crypto/openssl-android/crypto/dso/dso_dlfcn.c:455: error: 'dli' undeclared (first use in this function)
make: *** [obj/local/armeabi/objs/crypto/dso/dso_dlfcn.o] Error 1
As per error message- Dl_info is not defined. but if we go to file dso_dlfcn.c , the definition for the structure is already provided. (https://github.com/eighthave/openssl-android/blob/master/crypto/dso/dso_dlfcn.c)
And this code compiled for target=android-8 in default properties file, but not for android-7 or android-5.
Request you to help me to resolve this error. and let me know what all changes needs to be done in order to compile it for android 2.1 platform.
Thanks in advance.
Try to include the following piece of code into dso_dlfcn.c:
typedef struct {
const char *dli_fname; /* Pathname of shared object that
contains address */
void *dli_fbase; /* Address at which shared object
is loaded */
const char *dli_sname; /* Name of nearest symbol with address
lower than addr */
void *dli_saddr; /* Exact address of symbol named
in dli_sname */
} Dl_info;
int dladdr(const void *addr, Dl_info *info) { return 0; }
Before:
#ifdef __linux
# ifndef _GNU_SOURCE
# define _GNU_SOURCE /* make sure dladdr is declared */
# endif
#endif
After that in my case the library is built.
Try to install with latest NDK version and update Application.mk file appropriately.
LOCAL_PATH := $(call my-dir)
APP_PLATFORM := android-19
NDK_TOOLCHAIN_VERSION := clang
APP_ABI := armeabi-v7a
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -DANDROID
APP_PROJECT_PATH := $(shell pwd)
APP_BUILD_SCRIPT := $(LOCAL_PATH)/../Android.mk
The above 2 problems will be solved.
I had one issue with #Yuri's solution and had to improve it alittle. My APP_ABI is set to all in Application.mk. In my case it meant that among armeabi and armeabi-v7a I'm building also for x86 and mips. I have also android-9 target installed in android sdk to use in other projects. x86 and mips are supported by ndk starting from android-9. As written in the docs, when ndk-build will start building these targets, it will switch to android-9 target automatically. And what? - Yes, it will fail to compile :-). Here is my solution:
In crypto/Android.mk find the line local_c_flags :=
-DNO_WINDOWS_BRAINDEATH. After the line write this http://pastebin.com/7euUVD7A.
Yuri's code has to be inserted into if defined: http://pastebin.com/V58gTSBU
By the way, I've inserted Yuri's block after #include <openssl/dso.h> but not before #ifdef __linux