Problem of compiling build_native.sh

I’m a beginner of cocos2dx. When I was setting the project with cygwin, I faced the following error. I have no idea why it happened. May anyone help me?

$ ./build_native.sh
NDK_ROOT = /cygdrive/C/androidpackage/android-ndk-r9
COCOS2DX_ROOT = /cygdrive/c/cocos2d-x-2.1.4/testing/proj.android/…/…
APP_ROOT = /cygdrive/c/cocos2d-x-2.1.4/testing/proj.android/…
APP_ANDROID_ROOT = /cygdrive/c/cocos2d-x-2.1.4/testing/proj.android
Using prebuilt externals
Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
Android NDK: WARNING:/cygdrive/c/cocos2d-x-2.1.4/testing/proj.android/…/…/cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libra ries
make: Entering directory `/cygdrive/c/cocos2d-x-2.1.4/testing/proj.android’
Compile++ thumb : cocos2dx_static <= CCCommon.cpp
C:/cocos2d-x-2.1.4/testing/proj.android/…/…/cocos2dx/platform/android/CCCommon.cpp: In function ‘void cocos2d::CCLog(char const**, …)’:
C:/cocos2d-x-2.1.4/testing/proj.android/…/…/cocos2dx/platform/android/CCCommon.cpp:44:72: error: format not a string literal and no format arguments
C:/cocos2d-x-2.1.4/testing/proj.android/…/…/cocos2dx/platform/android/CCCommon.cpp: In function ’void cocos2d::CCLuaLog’:
C:/cocos2d-x-2.1.4/testing/proj.android/…/…/cocos2dx/platform/android/CCCommon.cpp:54:77: error: format not a string literal and no format arguments
cc1plus.exe: some warnings being treated as errors
/cygdrive/C/androidpackage/android-ndk-r9/build/core/build-binary.mk:348: recipe for target `obj/local/armeabi/objs/cocos2dx_static/platform/android/CCCommon.o’ failed
make:**** [obj/local/armeabi/objs/cocos2dx_static/platform/android/CCCommon.o] Error 1
make: Leaving directory `/cygdrive/c/cocos2d-x-2.1.4/testing/proj.android’

Put this line in your Android.mk file.

LOCAL_CFLAGS := -w

Thank you for your reply. However, the problem cannot be solved. It still exists.

It’s a problem with android-ndk-r9, try to get r8e for now.

Also you should download android-8 with SDK manager or set minimum to android-14.

I met the same error.

[dongsong@localhost proj.android]$ ./build_native.sh 
NDK_ROOT = /data/android/android-ndk-r9
COCOS2DX_ROOT = /data/android/cocos2d-x-2.1.4/HelloWorld/proj.android/../..
APP_ROOT = /data/android/cocos2d-x-2.1.4/HelloWorld/proj.android/..
APP_ANDROID_ROOT = /data/android/cocos2d-x-2.1.4/HelloWorld/proj.android
Using prebuilt externals
Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml    
Android NDK: WARNING:/data/android/cocos2d-x-2.1.4/HelloWorld/proj.android/../../cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries    
make: Entering directory `/data/android/cocos2d-x-2.1.4/HelloWorld/proj.android'
Compile++ thumb  : game_shared <= main.cpp
Compile++ thumb  : game_shared <= AppDelegate.cpp
Compile++ thumb  : game_shared <= HelloWorldScene.cpp
...
Compile++ thumb  : cocos2dx_static <= CCCommon.cpp
/data/android/cocos2d-x-2.1.4/HelloWorld/proj.android/../../cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLog(char const*, ...)':
/data/android/cocos2d-x-2.1.4/HelloWorld/proj.android/../../cocos2dx/platform/android/CCCommon.cpp:44:72: error: format not a string literal and no format arguments [-Werror=format-security]
/data/android/cocos2d-x-2.1.4/HelloWorld/proj.android/../../cocos2dx/platform/android/CCCommon.cpp: In function 'void cocos2d::CCLuaLog(char const*)':
/data/android/cocos2d-x-2.1.4/HelloWorld/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

make: *** [obj/local/armeabi/objs/cocos2dx_static/platform/android/CCCommon.o] Error 1
make: Leaving directory `/data/android/cocos2d-x-2.1.4/HelloWorld/proj.android'

http://dl.google.com/android/ndk/android-ndk-r8e-linux-x86_64.tar.bz2
It works… ndk r8e

Is is solved. Thank you :slight_smile:

Oops. I have had to delete my previous message due to stupid mistake.

So, to workaround this problem you should add -Wformat=0 to APP_CPPFLAGS in Application.mk
However, I believe the proper fix of this problem is to take those warnings into account and bring the code to a proper state.

CCCommon.cpp line 44

change android_log_print; // error in ndk9
to
android_log_print(ANDROID_LOG_DEBUG, “cocos2d-x debug info”, “%s”, buf);

I put this in my Application.mk to solve the same problem.
APP_CFLAGS += -Wno-error=format-security

I’ve also found necessary to use APP_CPPFLAGS += -Wno-error=format-security.

I’ve seen some commits on github about this, so it shouldn’t bother on next versions :slight_smile:

ok, some problem to me.
And I’ve try both way show upon, and never get it done.
suck^

problem remain! I don’t wanna change the ndk to r8e any way. any way else?

Post your error log so we can diagnose the problem.

I met similar question with environment ADT-Eclipse, andriod_ndk_9, when I compiling example project “HelloCpp” in cocos2d-x 2.1.5. There are only those warning info, but if I ignore it and run the application, can only show black screen without any info.

And I can compile and run it under visual studio dev environment. I config it by

*`` *** Build of configuration Default for project HelloCpp ****

bash C:/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/build_native.sh
NDK_ROOT = d:\android-ndk-r9
COCOS2DX_ROOT = /cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…
APP_ROOT = /cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…
APP_ANDROID_ROOT = /cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android
Using prebuilt externals

  • ‘d:\android-ndk-r9/ndk-build’ -C /cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android NDK_MODULE_PATH=/cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…:/cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…/cocos2dx/platform/third_party/android/prebuilt
    Android NDK: WARNING:/cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…/cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries
    make: Entering directory `/cygdrive/c/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android’
    Cygwin : Generating dependency file converter script
    Compile++ thumb : hellocpp_shared <= main.cpp
    Compile++ thumb : hellocpp_shared <= AppDelegate.cpp

    C:/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…/cocos2dx/kazmath/src/quaternion.c: In function ‘kmQuaternionAssign’:
    C:/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…/cocos2dx/kazmath/src/quaternion.c:478:5: warning: incompatible implicit declaration of built-in function ‘memcpy’ [enabled by default]
    C:/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…/cocos2dx/kazmath/src/vec4.c: In function ‘kmVec4Assign’:
    C:/cocos2d-x-2.1.5/samples/Cpp/HelloCpp/proj.android/…/…/…/…/cocos2dx/kazmath/src/vec4.c:150:5: warning: incompatible implicit declaration of built-in function ‘memcpy’ [enabled by default]

``*

It’s caused by android-ndk-r9, you could delete -Werror=format-security from android-ndk-r9/build/core/default-build-commands.mk

Red Zhen wrote:

It’s caused by android-ndk-r9, you could delete -Werror=format-security from android-ndk-r9/build/core/default-build-commands.mk

It’s not NDK, it’s Cocos2dx. Those errors/warnings are not an empty sound, they are important. The only correct solution is too fix the errors, not to make the compiler shut up.

dot squid wrote:

Red Zhen wrote:
> It’s caused by android-ndk-r9, you could delete Werror=format-security from android-ndk-r9/build/core/default-build-commands.mk
>
It’s not NDK, it’s Cocos2dx. Those errors/warnings are not an empty sound, they are important. The only correct solution is too fix the errors, not to make the compiler shut up.
it’s ndk,i’m delete
Werror=format-security compiler passed

A J wrote:

it’s ndk,i’m delete -Werror=format-security compiler passed

Yeah, right, in addition disable all warnings: that’s definitely a true way.

android-ndk-r8b/build/core/prebuilt-library.mk:64: * target pattern contains no ‘%’。 停止。

How can i resolve this problem?