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

AndroidAndroid Resources

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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>

Solution 2 - Android

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.

Solution 3 - Android

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRalf WickumView Question on Stackoverflow
Solution 1 - AndroidLucas De Morais CabralesView Answer on Stackoverflow
Solution 2 - AndroidAlanView Answer on Stackoverflow
Solution 3 - AndroidthegirlincodeView Answer on Stackoverflow