Android: suddenly, an AAPT error on multi-argument formatted strings

Viewed 1400

Similar questions have been answered several times already, and I did check many of those. This is different, please, read on.

I have a (large) number of strings defined in strings.xml with multiple format arguments. For example:

<string name="my_fmt_string">%s and also %s</string>

This causes an AAPT error

AAPT: warn: multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?

As I stated above, numerous questions about this have been asked and answered in SO. Those answers refer to using positonal syntax (%1$s) and formatted=false.

Thing is, those questions go as far back as 2010, while my application is 4 years old and compiled perfectly until I tried it today. No recent change points to a problem, certainly not since the last time I compiled this -- 3 days ago, on friday.

I have many, many formatted strings in my app. Fixing each case is tedious, and even difficult (what about complex formats like %02d? what if use a mix of String.format and context.getString(id, ...args)?).

What's changed? Why is it suddenly failing?

1 Answers

Okay then. OP here.

I walked back git history until I found a valid build. All of the AAPT messages were warnings at that point.

The old warnings were reported as errors in Android Studio's UI when I introduced a syntax error somewhere else: an unescaped apostrophe (' instead of \')

The endless cascade of errors made this hard to spot, since suddenly dozens upon dozens of strings were reported as failures in the build log. Walking them 1 by 1, I found the one that differed.

So, if you're reading this: disregard these messages, find the other error.

Related