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
Related
i will run a cocos project in android Studio but when type command cocos compile -p android in cmd.exe say error in ndk.
and android.mk is :
LOCAL_PATH := $(call my-dir)
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)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END
LOCAL_STATIC_LIBRARIES := cocos2dx_static
# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END
my cmd
As now According to me you are using NDK 12 or greater.
These NDK by default add arm64-v8a architecture support. You don't have libfreetype.a file in cocos2d/external/freetype2/prebuilt/android/arm64-v8a/ folder because cocos2d not generate by default, it slow down the compiling speed.
Solution is you can use NDK 11 or lesser
otherwise use latest version of cocos2d-x and enable ABI support to all arch armeabi armeabi-v7a x86 arm64-v8a instead of armeabi only
Some of concerning topic/issue
https://github.com/cocos2d/cocos2d-x/issues/15713
https://github.com/cocos2d/cocos2d-x/issues/15566
Hello i'm new to NDK and C/C++ development with android application. i'm having problem in my android application in compiling android application with c/c++.. I added some custom libraries for my sqlite. Could anyone explain what's happening to my project and is there something that i need to configure with my MK file? i added this to my mk file APP_ABI := armeabi armeabi-v7a
Here is my Android.mk file
APP_PLATFORM := android-8
#WHAT DO I NEED..
APP_ABI := armeabi armeabi-v7a
#TARGET_ARCH = arm
#TARGET_ARCH_ABI = armeabi-v7a
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ExtFunc
LOCAL_SRC_FILES := extension-functions.c
LOCAL_SRC_FILES += sqlite3.c
LOCAL_SHARE_LIBRARIES := sqlite3
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ProximityAPI
LOCAL_SRC_FILES := ProximitySearch.c
LOCAL_SRC_FILES += sqlite3.c
LOCAL_SHARE_LIBRARIES := sqlite3
include $(BUILD_SHARED_LIBRARY)
When i started running my project the armeabi-v7a libraries
automatically removed in compilation.
I used NDK R10b
To make things clear the two library is working in different project but when i combine them it removed my HERE-Map Libraries under the armeabi-v7a in compiling my android application.
Hope someone could help me i'm confused..
Thanks!
APP_ABI should go into your Application.mk file within the jni folder. It might not exist by default so you might have to create one. Also, if you are building only for ARM there is no need to specify that explicitly. If you are looking to target multiple architecture like x86 you could add that to you APP_ABI parameter.
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.
Now I have a so file which developed by DNK. I want to call the so file use C in Linux. But it always prompts:
[root#PCGiter Code]# gcc SoTest2.c -o SoTest2.exe -ldl
[root#PCGiter Code]# ./SoTest2.exe
Open Error:libcom_wuba_aes_ExecV3_1_0.so: cannot open shared object file: No such file or directory.
This answer is for creating the executables for Android and executing them in shell like in Linux, but not how to execute Android executables in Linux.
Use Android-ndk for building the source files, then you can copy directly to emulator and execute in the adb shell.
Example of the make file for creating an executable for android
# For building the Test executable
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Linker flags
LOCAL_LDLIBS += -llog
LOCAL_LDLIBS += -lOpenSLES
LOCAL_LDLIBS += -landroid
# Include paths
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)
# Local C Flags if any
LOCAL_CFLAGS :=
# Source Files to compile
LOCAL_SRC_FILES := \
# Shared libraries to be used while linking
LOCAL_SHARED_LIBRARIES :=
# Local module name
LOCAL_MODULE :=
include $(BUILD_EXECUTABLE)
You can get in to the emulator shell by launching the emulator and then executing the command in command prompt "adb shell" .
Usually what I observed is when copied to /data/ folder only, I was able to execute. Other folders such as /mnt/sdcard I was not able to execute the executable.
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.