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

升级Firebase依赖后Gradle构建报错:Content is not allowed in prolog

Fixing Gradle Build Error: "Content is not allowed in prolog"

Hey there, let's work through this frustrating build error you're hitting after updating your Firebase dependencies and the Google Services plugin. I've looked over your configs and logs, and here are the key fixes to try, ordered by how likely they are to resolve the issue:

1. Fix the Syntax Typo in Your App-level Gradle Script

First up, I spotted a small but critical typo in your build.gradle(Module:app) file. The last line is missing a closing single quote, which can throw off Gradle's parsing entirely:

// Wrong (missing closing quote)
apply plugin: 'com.google.gms.google-service

// Correct version
apply plugin: 'com.google.gms.google-services'

2. Inspect Your google-services.json File

The "Content is not allowed in prolog" error almost always points to a malformed JSON/XML file, and your Firebase google-services.json is the prime suspect here. Check for these common issues:

  • Leading whitespace or hidden characters: Open the file in a plain text editor (like VS Code or Notepad++) and make sure the first character is {—no extra spaces, newlines, or hidden byte order marks at the start.
  • Corrupted download: If the file was saved incorrectly from Firebase Console, re-download a fresh copy and replace the one in your app/ directory.
  • Incorrect placement: Ensure the file is directly in the app/ folder (same level as your app's build.gradle), not nested in a subfolder.

3. Upgrade the Google Services Plugin Version

Your current plugin version (3.3.1) is quite outdated and likely incompatible with the newer Firebase dependencies you're using (15.x series). Update it to a version that matches your Firebase library versions. For 15.x Firebase dependencies, a compatible plugin version is 4.3.10:
In your project-level build.gradle, change this line:

classpath 'com.google.gms:google-services:3.3.1'

// Replace with
classpath 'com.google.gms:google-services:4.3.10'

4. Clean and Rebuild Your Project

After making the above changes, clear any cached bad data with a full clean:

  1. Go to Build > Clean Project in Android Studio
  2. Then run Build > Rebuild Project
  3. If the error persists, delete the .gradle folders (both in your project root and the app/ module), then click File > Sync Project with Gradle Files to start fresh.

5. Check Other XML Config Files

Occasionally, malformed XML files in your project (like AndroidManifest.xml, strings.xml, or layout files) can trigger this error too. Double-check these files to ensure they have valid XML syntax, no leading spaces, and aren't corrupted.


内容的提问来源于stack exchange,提问作者Dhruv Verma

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 06:47:20