as3.0以上在gradle.properties使用android.enableAapt2=true,as就会提示将要过期了,请设置成
android.enableAapt2=false。当我设置成false啦,这时候编译出错误。
Multiple substitutions specified in non-positional format; did you mean to add the formatted="false"
就是当你的string.xml上含有要格式的字符串比如
<string name="time_picker">%s时</string>
这时候会提示上述错误,因为sdk采用了更加严格的aapt编译,正确的用法如下
If you need to format your strings using String.format(String, Object...) , then you can do so by putting your format arguments in the string resource. For example, with the following resource:
In this example, the format string has two arguments: %1$s is a string and %2$d is a decimal number. You can format the string with arguements from your application like this:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
解决方法:
之前我们用的%s 改为%1$s,如果在一个字符串有两个%s,%s。现在要改为%1$s,%2$s,重新编译没ok了。
拓展
如果字符串含有%,而不需要格式化可以有三种方法解决
- 加上formatted="false"
<string name="time_picker" formatted="false">%s时</string>
- 用两个%%
<string name="time_picker">%%s时</string>
- 用转义字符\
<string name="time_picker" >\%s时</string>
网友评论