# android strings.xml Error: bad escape sequence in quantity string

## TL;DR

Fixes the Android resource compile error when a plurals quantity string contains a bad escape. Use only supported escapes like newline and unicode in quantity strings. Use when aapt reports a bad escape in plurals. Not for apostrophe issues in plain strings.

## The error

```text
Error: bad escape sequence in quantity string at line 31 of values/strings.xml
```

## Fix it

### Step 1: Open the reported line

```bash
sed -n '28,34p' app/src/main/res/values/strings.xml
```

Expected: You see the quantity string with the bad escape.

### Step 2: Replace it with a supported escape

```bash
node -e "console.log('use a newline escape or a unicode escape instead of the unsupported one')"
```

Expected: The quantity string uses only valid escapes.

### Step 3: Rebuild resources

```bash
./gradlew assembleDebug | tail -3
```

Expected: The resource compile succeeds.

## When to use this

- aapt reports a bad escape sequence in a quantity string
- A plurals entry was edited by hand

## When NOT to use this

- The error is about apostrophes, escape those differently
- The string compiles but renders wrong, check the format arguments

## Tool and version compatibility

- Android Gradle Plugin 8
- aapt2

## Variant phrasings

### error after a translator edited the file

Translators sometimes add literal backslashes. Validate XML escapes in TMS QA.

### error only in one quantity form

Only the few or many entry has the bad escape. Check each form.

## Why it happens

Android quantity strings go through a stricter escape parser than plain strings. An escape the parser does not recognize aborts resource compilation for the whole file.

## Edge cases

- CDATA sections do not exempt quantity strings from escape rules
- Unicode escapes are the safest way to include special characters
- Lint does not catch this; only the aapt compile step does

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_kLWB1LQdsrOEqZ22kNafMA
