Ralf Wickum
Ralf Wickum

Reputation: 3270

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

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?

Upvotes: 80

Views: 45619

Answers (4)

Eeshvar Das
Eeshvar Das

Reputation: 11

A substitution is marked by a percent sign so any percent sign may cause this error if the percent sign is not properly substituted.

The percent sign is an invalid XML character unless it is properly used for substitution In this file format.

Type the word percent instead of using the symbol.

Upvotes: 0

thegirlincode
thegirlincode

Reputation: 404

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.

Upvotes: 6

Alan
Alan

Reputation: 687

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.

Upvotes: 11

Lucas Cabrales
Lucas Cabrales

Reputation: 2163

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>

Upvotes: 175

Related Questions