在Android Studio上部署Flutter时出现Prolog错误

移动开发 2026-07-11

我正在尝试把我的第一个Flutter应用部署到VS Code、IntelliJ或 Android Studio的 Android模拟器上。它们都给出同样的错误。我一直在查找解决方法,但找不到。尝试在一个中等配置的Android模拟器上进行部署。我的应用在网页版本上运行正常。第一次尝试时,我的电脑崩溃了。自那以后,即使执行flutter clean也会出现这个错误。我已经运行过flutter doctor,结果显示一切正常,除了未安装Visual Studio。我也尝试过重新创建Android文件夹,但没有效果。

Launching lib main.dart on sdk gphone64 x86 64 in debug mode...

Running Gradle task 'assembleDebug'...

[Fatal Error] gradle-settings-api-8.13.1.pom:2:1: Content is not allowed in prolog.

[Fatal Error] android-test-plugin-host-logcat-proto-31.13.1.pom:2:1: Content is not allowed in prolog.

[Fatal Error] baseLibrary-8.13.1.pom:2:1: Content is not allowed in prolog.

[Fatal Error] builder-test-api-8.13.1.pom:2:1: Content is not allowed in prolog.

[Fatal Error] sdk-common-31.13.1.pom:2:1: Content is not allowed in prolog.

<many more of these above followed by>
* What went wrong:
A problem occurred configuring project ':shared_preferences_android'.
> Could not resolve all artifacts for configuration 'classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.0.
     Required by:
         project :shared_preferences_android
      > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.0.
         > Could not parse POM https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/2.3.0/kotlin-gradle-plugin-2.3.0.pom
            > Resetting to invalid mark
   > Could not resolve com.android.tools.build:gradle-settings-api:8.13.1.
     Required by:
         project :shared_preferences_android > com.android.tools.build:gradle:8.13.1
      > Could not resolve com.android.tools.build:gradle-settings-api:8.13.1.
         > Could not parse POM https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle-settings-api/8.13.1/gradle-settings-api-8.13.1.pom
            > Content is not allowed in prolog.
   > Could not resolve com.android.tools:sdk-common:31.13.1.
     Required by:
         project :shared_preferences_android > com.android.tools.build:gradle:8.13.1
      > Could not resolve com.android.tools:sdk-common:31.13.1.
         > Could not parse POM https://dl.google.com/dl/android/maven2/com/android/tools/sdk-common/31.13.1/sdk-common-31.13.1.pom
            > Content is not allowed in prolog.
Many more lines like the prolog line above. Here is my pubspec.yaml
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
  sdk: ^3.9.2

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.8
  http: ^1.5.0
  flutter_stripe: ^12.4.0
  flutter_stripe_web: ^7.4.0
  shared_preferences: ^2.5.4


dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^6.0.0

flutter:
  uses-material-design: true
  assets:
    - assets/images/


And my build.gradle.kts
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

val newBuildDir: Directory =
    rootProject.layout.buildDirectory
        .dir("../../build")
        .get()
rootProject.layout.buildDirectory.value(newBuildDir)

subprojects {
    val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
    project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
    project.evaluationDependsOn(":app")
}

tasks.register<Delete>("clean") {
    delete(rootProject.layout.buildDirectory)
}

解决方案

我曾经遇到过这个错误一次 我通过修改Kotlin Gradle插件版本和AGP版本来解决的

但如果仍然不行,可以尝试在另一台电脑上运行你的项目。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章