Android studio2.2 ndk 错误 :format not a string literal and no format arguments!

在Android Studio2.2 进行NDK编程,在对*char 字符串 进行日志输出时,报错:

error: format not a string literal and no format arguments [-Werror=format-security]

 

 

代码:

 

 

网上说是版本不兼容导致的!搜索了下解决 方法如下:

解决方法:

在你的ndk目录下修改build/core/default-build-commands.mk

TARGET_FORMAT_STRING_CFLAGS := -Wformat -Werror=format-security

TARGET_FORMAT_STRING_CFLAGS := -Wformat   #-Werror=format-security

也就是把后面部分用#号注释掉

 

 

在 在Application.mk里面添加下面代码
APP_CPPFLAGS += -Wno-error=format-security

加入之后确实ok了。编译通过了。

但是这个修改后,报运行错误 !

最后通过修改代码

把env->GetStringUTFChars(name_,0);

改成:

Env->GetStringUTFChars(name_NULL);

如下图:

 

 

运 行,通过!





原文地址:https://www.cnblogs.com/ut2016-progam/p/6066848.html