You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio Gradle同步失败求助:Manifest XML解析错误

Fixing Gradle Sync Error Caused by Malformed AndroidManifest.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.0 dependency—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

  1. Save the corrected AndroidManifest.xml file.
  2. Clean up the duplicate/mixed dependencies in build.gradle.
  3. Try syncing Gradle again—this should resolve the parse error and complete the sync successfully.

内容的提问来源于stack exchange,提问作者CodeChris B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 22:22:29