Android Studio升级后出现AAPT2错误,求助排查AndroidManifest.xml问题
Absolutely, I’ve dealt with my fair share of AAPT2 issues linked to AndroidManifest.xml after Studio upgrades—they’re usually tied to stricter syntax checks or version mismatches. Let’s walk through the most common fixes and checks:
First, Grab the Full AAPT2 Error Details
AAPT2 almost always outputs specific line numbers or root causes in the Gradle Console (look for entries labeled "AAPT2 error"). Don’t stop at the generic error message—expand the logs to see exactly what’s breaking the build. This will cut down on guesswork drastically.
Fix Truncated & Basic Syntax Issues in Your Manifest
Looking at the snippet you shared, your android:vers... line is clearly cut off. This is a critical problem—make sure you fully define both android:versionCode (you have this set to "1") and android:versionName (e.g., android:versionName="1.0"). Missing or incomplete attributes will immediately throw AAPT2 off.
Other quick syntax checks:
- Confirm all XML tags are properly closed (no unclosed
<activity>or<service>tags hanging around) - Verify the root
manifesttag has the correct namespace:xmlns:android="http://schemas.android.com/apk/res/android" - Watch for typos in attribute names (e.g.,
android:launchModeinstead ofandroid:launchmode) - Escape special characters like
&,<, or>in strings (use&,<,>respectively—AAPT2 is strict about this)
Align Gradle Plugin & SDK Versions With Your Studio Upgrade
When you update Android Studio, it often nudges you to upgrade the Gradle Plugin and compile SDK version. Mismatches here are a top cause of post-upgrade AAPT2 failures:
- Open your project-level
build.gradleand make sure the Gradle Plugin version matches your Studio release (e.g., Studio Hedgehog uses plugin8.2.x) - In your app module’s
build.gradle, setcompileSdkandtargetSdkto a version compatible with the plugin (usually the latest stable SDK)
Clear Corrupted Build Caches
Post-upgrade glitches often stem from cached build files. Try these steps to reset:
- Run the clean command in your terminal:
./gradlew clean - In Android Studio, go to File > Invalidate Caches... > Invalidate and Restart
- Delete the
.gradlefolder in your project root and thebuildfolders in all modules
Resolve Manifest Merge Conflicts (For Multi-Module Projects)
If your app uses libraries or multiple modules, conflicting entries in merged manifests can trigger AAPT2 errors. Look for logs like "Attribute android:icon@value is also present". Fix these by:
- Using
tools:replacein your app’s manifest to override conflicting attributes (e.g.,<application tools:replace="android:icon, android:theme">) - Removing redundant entries from library manifests with
tools:remove
Validate the Full Manifest Structure
Double-check that all components are nested correctly:
<activity>,<service>,<receiver>must live inside the<application>tag<uses-permission>,<uses-feature>should be direct children of the root<manifest>tag- Ensure no duplicate component names (e.g., two activities with the same
android:name)
If you can share your full, untruncated AndroidManifest.xml and the complete AAPT2 error log, I can help pinpoint the exact issue.
内容的提问来源于stack exchange,提问作者Christian Bohli

