65

I have an Android app, which throws on BUILD process following error:

/home/Ralf/Projekte/University/android-sampleapp/sampleapp/build/intermediates/bundles/debug/res/values-de/values-de.xml Error:(88, 5) Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? Error:(88, 5) Unexpected end tag string

/home/Ralf/Projekte/University/android-sampleapp/sampleapp/build/intermediates/bundles/debug/res/values/values.xml Error:(106, 5) Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? Error:(106, 5) Unexpected end tag string

/home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/res/merged/debug/values-de/values-de.xml Error:(131) Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? Error:(131) Unexpected end tag string

/home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/res/merged/debug/values/values.xml Error:(1258) Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? Error:(1258) Unexpected end tag string Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing process /opt/sdk/build-tools/26.0.2/aapt with arguments {package -f --no-crunch -I /opt/sdk/platforms/android-27/android.jar -M /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/manifests/full/debug/AndroidManifest.xml -S /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/res/merged/debug -m -J /home/Ralf/Projekte/University/android-sampleapp/demo/build/generated/source/r/debug -F /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/res/debug/resources-debug.ap_ -D /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/multi-dex/debug/manifest_keep.txt --custom-package com.ralfi.demo -0 apk --output-text-symbols /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/symbols/debug --no-version-vectors} Error:com.android.ide.common.process.ProcessException: Error while executing process /opt/sdk/build-tools/26.0.2/aapt with arguments {package -f --no-crunch -I /opt/sdk/platforms/android-27/android.jar -M /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/manifests/full/debug/AndroidManifest.xml -S /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/res/merged/debug -m -J /home/Ralf/Projekte/University/android-sampleapp/demo/build/generated/source/r/debug -F /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/res/debug/resources-debug.ap_ -D /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/multi-dex/debug/manifest_keep.txt --custom-package com.ralfi.demo -0 apk --output-text-symbols /home/Ralf/Projekte/University/android-sampleapp/demo/build/intermediates/symbols/debug --no-version-vectors} Error:org.gradle.process.internal.ExecException: Process 'command '/opt/sdk/build-tools/26.0.2/aapt'' finished with non-zero exit value 1

When I click on the errors at the string resrouces, it points to: Hide for %02d:%02d min

But I need a translation for those resources, why am I getting this?

Community
  • 1
  • 1
Ralf Wickum
  • 1,940
  • 6
  • 40
  • 77

3 Answers3

133

That is because your String resource has multiple %s or similar. To avoid this, you must identify each like this: %1$s. Example:

<string name="full_name">First: %1$s - Last: %2$s</string>

Where %1$s is your first substitution and %2$s is your second.

If you do not mean to perform any substitution, just add the attribute formatted="false". Example:

<string name="your_string" formatted="false">Level: 100%</string>

Lucas De Morais Cabrales
  • 1,745
  • 1
  • 11
  • 21
  • I already have changed to: Two values %02d:%02d – Ralf Wickum Jan 22 '18 at 10:49
  • 1
    Add the "formatted" attribute, like this: `Two values %02d:%02d` – Lucas De Morais Cabrales Jan 22 '18 at 14:05
  • 2
    Very useful answer, Thanks very much for solving my problem – Karue Benson Karue Mar 13 '18 at 12:58
  • 12
    I have multiple Language files with hundreds of strings. Is there another overriding setting somewhere that can be set rather than altering each and every line. This actually only occurred after upgrading Gradle and Studio. – Mark Anderson Aug 12 '19 at 04:14
  • Thanks for the answer. That worked, Because sometimes you do not need `%1$s` version of formatter. – sud007 Oct 04 '19 at 10:25
  • 1
    Our translated string resource files are regularly imported from phrase (a.k.a. phraseapp), we can't add formatted="false". How to disable this warning completely in gradle/aapt? – Luzian Jul 21 '21 at 10:08
  • Doing this replacement is just about doing a super-short sed script that replaces `%s` with `%1$s` for the first, and vice versa for the second and third and forth and ... You can run that as a build step (probably re-written to Kotlin) to avoid the manual step after importing from Phraseapp, @Luzian. – oligofren Sep 08 '21 at 22:04
  • Use Analyze >Inspect code to see errors. In my case, I had deleted one widget but there was remained some reference to its id and it made this problem on release. – faridfedora Apr 19 '22 at 05:38
6

Another possibility for this error when it has been a warning previously; There can be a different error hidden among these errors so you need to go find and fix that. There was a duplicate resource value error and somehow that trigger a lot of the 'Multiple substitutions specified in non-positional format' for me and finding and fixing the duplicate value error resolved the build problem.

Alan
  • 617
  • 5
  • 13
3

There may be other issues underlying this error. For example for me the single quotes (') I added in a string caused to get this problem. Using this single quote with backslash helped me solve the error. If you get this error after change something, please check these changes.

thegirlincode
  • 210
  • 2
  • 8
  • Use Analyze >Inspect code to see errors. In my case, I had deleted one widget but there was remained some reference to its id and it made this problem on release. – faridfedora Apr 19 '22 at 05:38