Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

The Android build stops with Failed to compile values file on a strings.xml or other values file

ErrorFailed to compile values file

Short answer

AAPT2 compiles every file in res/values on its own and stops at the first one it cannot parse. The error line names the file and line number. The usual culprit is text that needs escaping: an unescaped apostrophe or quote, a raw & or <, a string that starts with @ or ?, or a file that is not valid resources XML.

  • Applies to Android Gradle Plugin 8, Android Studio, AAPT2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Build from the terminal and read the lines that start with a file path and say error. They give the exact values file and line that AAPT2 rejected, which is faster than reading the whole Gradle output. Translation folders such as values-fr count too.

    ./gradlew assembleDebug
    ls app/src/main/res | grep '^values'
  2. 2Match what you see, then jump to its fix

    1. 1The failing line is a string that contains a single quote, as in Don't, or a double quote inside the textAn apostrophe or a double quote is not escapedFix
    2. 2The failing line holds & or < inside a string, for example in Terms & Conditions or a less-than signA raw ampersand or angle bracket is in the textFix
    3. 3The failing line is a string whose text begins with an at sign or a question mark, such as an @handleA string starts with @ or ?Fix
    4. 4The error names a line you did not expect, and the file was edited by hand, merged, or written by a toolThe file is not valid resources XMLFix

What does the error look like?

  • Failed to compile values file

Cause 1 of 4

An apostrophe or a double quote is not escaped

1Check

Android requires escaped apostrophes and quotation marks in string resources. A single quote needs a backslash, or the whole string must sit inside double quotes. A double quote needs a backslash, and surrounding the text with single quotes does not work. Every values folder has its own copy of the strings, so a translation such as values-fr can fail while the default file is fine.

grep -n "'" app/src/main/res/values*/strings.xml

2Fix

Escape the character, or wrap the string in double quotes.

<resources>
    <string name="stop_one">Don\'t stop</string>
    <string name="stop_two">"Don't stop"</string>
    <string name="said">He said \"stop\"</string>
</resources>

3Verify

Compile just that file with AAPT2 from the SDK build tools, then build the app.

mkdir -p compiled
aapt2 compile app/src/main/res/values/strings.xml -o compiled/
./gradlew assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 4

A raw ampersand or angle bracket is in the text

1Check

A values file is XML. The XML standard says & and < must not appear in literal form except as markup, and must be escaped as &amp; and &lt;. Android's documentation says the same for string resources. Look for & and < in the failing line.

grep -n -E '&[^a-z#]|<[^/a-z!?]' app/src/main/res/values*/*.xml

2Fix

Use the XML entities for the characters.

<resources>
    <string name="terms">Terms &amp; Conditions</string>
    <string name="limit">Value &lt; 10</string>
</resources>

3Verify

Compile the file and build again.

mkdir -p compiled
aapt2 compile app/src/main/res/values/strings.xml -o compiled/
./gradlew assembleDebug

Confirmed by w3.org

Did this fix it?

Cause 3 of 4

A string starts with @ or ?

1Check

In Android resources a leading @ or ? has a special meaning, so the character in plain text has to be escaped with a backslash.

grep -n -E '>[@?]' app/src/main/res/values*/*.xml

2Fix

Put a backslash in front of the character.

<resources>
    <string name="handle">\@example</string>
    <string name="question">\?</string>
</resources>

3Verify

Compile the file and build again.

./gradlew assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 4 of 4

The file is not valid resources XML

1Check

A string resource file needs a resources element as the root node. The XML standard adds that a document has exactly one root, that every start-tag is closed by an end-tag, and that elements nest properly; a processor stops on the first violation. A leftover merge conflict marker or a missing closing tag breaks that.

head -n 5 app/src/main/res/values/strings.xml
grep -n -E '^(<<<<<<<|=======|>>>>>>>)' app/src/main/res/values*/*.xml

2Fix

Restore the structure: one XML declaration, one resources root, and complete elements inside it.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">My App</string>
</resources>

3Verify

AAPT2 compiles the file without any output.

mkdir -p compiled
aapt2 compile app/src/main/res/values/strings.xml -o compiled/

Confirmed by w3.org

Did this fix it?

How do I stop it coming back?

  • Run a debug build before every push that touches a strings.xml, and after every merge of translation files.
  • Give translators a short note: apostrophes and double quotes need a backslash, an ampersand is written &amp;.
  • Keep one string per line, so the line number in the error tells you the string straight away.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.