迁移至Android Studio 3.1.1时遭遇AAPT错误::item>
Hey there, that frustratingly vague ":item>" error during Gradle sync after moving to Android Gradle Plugin 3.1.1 (with the stricter AAPT2 processor) is almost certainly tied to stricter XML validation in the new tooling. Let’s walk through actionable steps to track down and fix the issue:
1. Deep-Dive the Offending XML Lines (599-608 in styles.xml)
AAPT2 is way pickier about XML syntax than the old AAPT, so the problem is likely a tiny syntax glitch in those lines. Look for:
- Malformed
<item>tags: Did you accidentally type:item>instead of</item>for a closing tag? Or miss the opening<for an<item>entirely? - Unclosed nested tags: Are you nesting elements inside an
<item>that shouldn’t be there (like another<style>or<item>without proper closure)? - Missing quotes on attributes: For example,
android:color=#fffinstead ofandroid:color="#fff"— AAPT2 will flag this where the old tool might have let it slide.
2. Check for Unescaped Special Characters
AAPT2 enforces strict XML escaping rules. If your <item> values include characters like &, <, or >, they need to be replaced with their escaped equivalents:
&→&<→<>→>
Older AAPT versions might have ignored these, but AAPT2 will throw vague errors like the one you’re seeing if they’re present.
3. Wipe Caches and Do a Clean Rebuild
Corrupted build caches can cause weird, unexplained errors. Try these steps:
- Go to
File > Invalidate Caches / Restartin Android Studio and confirm the action. - Manually delete the
.gradleandbuildfolders in your project directory. - Reopen Android Studio, run a full Gradle sync, then do a clean rebuild (
Build > Clean Projectfollowed byBuild > Rebuild Project).
4. Validate Referenced Resources
If your <item> references another resource (like a drawable, color, or string), double-check:
- The resource exists and has a valid filename (AAPT2 disallows uppercase letters, spaces, or special characters in resource filenames).
- There are no typos in the resource reference (e.g.,
@color/whiteeinstead of@color/white). - The resource itself isn’t corrupted (e.g., a drawable XML with its own syntax errors).
5. Isolate the Problem by Commenting Code
If you still can’t spot the issue, temporarily comment out the entire block from line 599 to 608. If the sync succeeds, uncomment lines one by one (or in small chunks) and re-sync each time. This will help you pinpoint the exact line causing the error.
内容的提问来源于stack exchange,提问作者Johan Paul

