Android Studio Gradle同步失败求助:Manifest XML解析错误
Hey there, let’s get this sorted out for you! The error you’re seeing isn’t actually a core Gradle issue—Gradle sync is failing because it can’t parse your invalid AndroidManifest.xml file. Let’s break down the problem and fix it step by step.
The Root Cause: Invalid XML Syntax in Manifest
Looking at your manifest code, the error points to line 19, column 13. That’s where you’ve got a misplaced attribute in your MainActivity declaration:
<activity android:name="com.example.foodgent.UserInterface.MainActivity" android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize" <!-- This line is invalid! -->
You duplicated the android:windowSoftInputMode attribute and placed it inside the activity tag body instead of keeping it in the opening tag. XML doesn’t allow floating attribute declarations like this—it expects proper start/end tags or nested elements here.
Fix the Manifest File
Replace the broken MainActivity section with this corrected code:
<activity android:name="com.example.foodgent.UserInterface.MainActivity" android:windowSoftInputMode="adjustResize"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>
Bonus: Clean Up Your build.gradle to Avoid Future Issues
While we’re troubleshooting, I noticed a couple of red flags in your dependencies that could cause conflicts later:
- You’ve duplicated the
androidx.appcompat:appcompat:1.1.0dependency—remove one instance of it. - You’re mixing AndroidX AppCompat (
androidx.appcompat:appcompat) and the old support library version (com.android.support:appcompat-v7:22.0.0). These two don’t play well together—delete the old support library dependency entirely since you’re already using AndroidX.
Final Steps
- Save the corrected
AndroidManifest.xmlfile. - Clean up the duplicate/mixed dependencies in
build.gradle. - Try syncing Gradle again—this should resolve the parse error and complete the sync successfully.
内容的提问来源于stack exchange,提问作者CodeChris B

