I'm trying to disable all warnings during the 'ndk-build' process for compiling CPP code to be used with JNI on Android.
I'm using LOCAL_CFLAGS := -Wno-error with not success.
Any ideas?
Thanks
OK. Got it. Put this line in your Android.mk file.
LOCAL_CFLAGS := -w
Hope it helps
Related
So I am trying this app by Eaglesky in Android Studio:
https://github.com/eaglesky/HandGestureApp
but got an error when using right-clicking and choosing ndk-build.
The Error
I was thinking this might be due to ndk no longer supports gnustl_static so I had to change it to c++_static and eventually got the error.
My Application.mk
APP_PLATFORM := android-16
APP_ABI := all
APP_CPPFLAGS := -frtti -fexceptions
APP_STL := c++_static
My apologize, I'm still quite new to Android Development.
Your problem is using:
APP_STL := c++_static
OpenCV requires gnuc library:
APP_STL := gnustl_shared
Make sure NDK tool chain is also gnu not clang.
I was able to successfully pass in APP_CFLAGS via eclipse through via the settings' ndk-build command as
ndk-build -B NDK_DEBUG=1 APP_CFLAGS=-DTEST
I have now switched to Android studio and was trying to do it directly in the makefile with the following, but its not taking:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
APP_CFLAGS += -DTEST
LOCAL_SRC_FILES:= test.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
It builds fine, but my TEST variable is never set in the C++ code.
How can I add it to the makefile?
Or, How can I add it to Android Studio project settings?
You could use LOCAL_CFLAGS for C/C++ code additional flags or LOCAL_CPPFLAGS for C++ code in Android build system.
LOCAL_CFLAGS := -DTEST=1
I've got an issue building my C++ code using NDK r9d, since I try to compile C files using C++ compiler (G++) I've got this warnings :
C:/Android/ndk/build/core/build-binary.mk:393: warning: overriding commands for target
C:/Android/ndk/build/core/build-binary.mk:391: warning: ignoring old commands for target
Before I didn't need to compile with C++ 11 and my C files was compiled with GCC, I had no problems, but since I had LOCAL_CPP_EXTENSION := .cpp .c, this warnings appears (only for C files).
I found that someone else had the same problem (Overriding commands for target Android Makefile) but didn't get any answer.
Here is my files :
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
MY_INC_PATH := ../../..
LOCAL_MODULE := test
LOCAL_CFLAGS := -Werror
LOCAL_CPPFLAGS := -std=c++11
LOCAL_LDLIBS := -ldl -llog -lGLESv1_CM
LOCAL_C_INCLUDES := \
$(MY_INC_PATH)
MY_SRC_PATH := ../../../..
LOCAL_CPP_EXTENSION := .cpp .c
LOCAL_SRC_FILES := \
$(MY_SRC_PATH)/XXX.c \
$(MY_SRC_PATH)/YYY.cpp \
$(MY_SRC_PATH)/ZZZ.cpp
include $(BUILD_SHARED_LIBRARY)
I use NDK r9d and compile with G++ 4.8 and C++ 11 activated. Thanks for your help.
As of r9d, NDK does not provide methods to unassociate .c files from C compiler. You can redefine $$(TARGET_CC), and also set LOCAL_CFLAGS += -std=c++11, and not set LOCAL_CPP_EXTENSION to include .c, but that would be a hack, anyways. So if you cannot rename the files, and do not want to hack your NDK, the cleanest solution would be to simply ignore the warning.
Background
OSX is OS
R8 NDK
I am trying to compile the following class using the Android GCC compiler...
#include <stdint.h>
int main (void){
return 0;
}
I do the with the following command...
un#un:~/Development/Code/OpenGL$ ~/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc hello.c -o hello
I get...
In file included from hello.c:1:0:
/Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/include/stdint.h:3:26: fatal error: stdint.h: No such file or directory
compilation terminated.
So due to a lack of gcc knowledge (but some Google ability) I find this and try it...
un#un:~/Development/Code/OpenGL$ ~/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc hello.c -o hello -ffreestanding
and I get...
/Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: ld returned 1 exit status
Can someone help me with what I am doing wrong? Am I missing a link or something? Android.mk is not an option.
UPDATE this isn't working either...
arm-linux-androideabi-gcc hello.c --sysroot=~/Development/Android/android-ndk-r8c/platforms/android-9/arch-arm
/Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: ld returned 1 exit status
You must tell GCC where to find the Android system files and headers. Either use:
ndk-build and an Android.mk with BUILD_EXECUTABLE
or, the --sysroot GCC option
[1]
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo.c
include $(BUILD_EXECUTABLE)
[2]
# Change `android-9` with the level you target
/path/to/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt\
/darwin-x86/bin/arm-linux-androideabi-gcc\
--sysroot /path/to/android-ndk-r8c/platforms/android-9/arch-arm/\
foo.c -o foo
# Or generate a ready-to-use standalone toolchain (better)
/path/to/android-ndk-r8c/build/tools/make-standalone-toolchain.sh \
--platform=android-9 \
--install-dir=/tmp/my-android-toolchain
export SYSROOT=/tmp/my-android-toolchain/sysroot
/path/to/arm-linux-androideabi-gcc --sysroot $SYSROOT foo.c -o foo
So, since I don't want to use Android.mk file, I went ahead and created a standalone toolchain. this is done using the following...
/Users/un/Downloads/android-ndk-r8d/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=/tmp/my-toolchain
/tmp/my-toolchain/bin/arm-linux-androideabi-gcc hello.c
I would like to know what the "alternative" is in terms of the gcc linking I could do.
This answer adds a bit more details to #deltheil's answer. I had similar issues as I was trying to compile I2C-tools for debugging I2C bus on Android. Somehow after struggling for more than a day with make files and trying different options including --sysroot & --dynamic-linker options etc., I finally tried to compile it within the Android AOSP tree. I used the Google Nexus-S AOSP to build a binary that I intended to run on Samsung S3 phone. I created a folder called i2c-tools for the sources inside the AOSP/external folder and copied Android.mk, Cleanspec.mk & MODULE_LICENCE from another executable folder (ping) and modified it for i2c-tools as follows:
ifneq ($(TARGET_SIMULATOR), true)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := i2cdetect.c i2cbusses.c
LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
LOCAL_MODULE := i2cdetect
LOCAL_MODULE_TAGS := tests
LOCAL_SHARED_LIBRARIES := libc
include $(BUILD_EXECUTABLE)
endif
Then I just ran:
source build/envsetup.sh
make i2cdetect
from the AOSP base folder and voila, I had a working executable in out/target/product/generic/system/bin/ folder. Note that I had to copy all needed source and header files from the original (i2c-tools)/tools & include folders and had to modify some of the #include to remove the extra path for header files that were now in the same place as the c-source.
In my case, I needed an .o file and did not need to define main().
I had to specify the -c switch:
~/ax/arm-linux-androideabi-g++ --sysroot=~/an/platforms/android-8/arch-arm/ -c dummy.c
where ~/ax and ~/an are links:
ax -> ~/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/
an -> ~/android-ndk-r9d/
did dummy.o.
i solved the problem ,
the default compress file manager in ubuntu wasn't extracting symbolic links ,
so i tried : tar jxf filename.tar.bz2
to untar the ndk.tar.bz2 and now it works fine
I am doing NDK profiling for my project using android-ndk-profiler-3.1. I have made changes in Android.mk as follows...
LOCAL_PATH := $(call my-dir)
-include android-ndk-profiler.mk
include $(CLEAR_VARS)
# Module name -------------------------------------------------------
LOCAL_CFLAGS += -O3
TARGET_ARCH_ABI :=armeabi
LOCAL_CFLAGS := -pg
LOCAL_STATIC_LIBRARIES := andprof
LOCAL_LDLIBS += -llog
LOCAL_MODULE := libitv
include $(BUILD_SHARED_LIBRARY)
Application.mk is as follows...
APP_ABI := armeabi
APP_PLATFORM := android-10
I have called monstartup("itv.so"); function in the beginning of the native code and moncleanup(); function in the stop method. And gmon.out file is created successfully.And then I have pasted gmon.out in
D:\android\android-ndk-r6-windows\android-ndk-r6\toolchains\arm-linux-androideabi-4.4.3\prebuilt\windows\bin directory.
But when I am trying to read gmon.out using the following command...
D:\android\android-ndk-r6-windows\android-ndk-r6\toolchains\arm-linux-androideab
i-4.4.3\prebuilt\windows\bin>arm-linux-androideabi-gprof D:\InternetTV_FD_Canvas
\libs\armeabi\libitv.so > out.txt
This Error is showing...
arm-linux-androideabi-gprof: file `D:\InternetTV_FD_Canvas\libs\armeabi\libitv.so'
has no symbols
I am not able to make out why this error is coming even I have done everything fine.
Can anybody please help me.
Any help will be appreciated.
Thanks in Advance.
The NDK build process creates 2 libraries, one with symbols and one stripped without. You install the stripped, symbol-less library in your APK, but you need to use the unstripped version with gprof. If you run:
arm-linux-androideabi-gprof D:\InternetTV_FD_Canvas\obj\local\armeabi\libitv.so
... then that should be the correct library.