【问题标题】:Content is not allowed in prolog during Gradle build在 Gradle 构建期间,prolog 中不允许有内容
【发布时间】:2018-04-13 21:42:55
【问题描述】:

我尝试了不同的方法但问题没有解决,我什至重新安装了 android studio 但仍然遇到同样的问题:

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

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'myapp'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools:annotations:26.1.1.
     Required by:
         project : > com.android.tools.build:gradle:3.1.1 > com.android.tools.build:gradle-core:3.1.1 > com.android.databinding:compilerCommon:3.1.1
      > Could not resolve com.android.tools:annotations:26.1.1.
         > Could not parse POM https://dl.google.com/dl/android/maven2/com/android/tools/annotations/26.1.1/annotations-26.1.1.pom
            > Content is not allowed in prolog.
   > Could not resolve com.android.tools:annotations:26.1.1.
     Required by:
         project : > com.android.tools.build:gradle:3.1.1 > com.android.tools.build:gradle-core:3.1.1 > com.android.tools.build:builder:3.1.1 > com.android.tools.build:builder-model:3.1.1
         project : > com.android.tools.build:gradle:3.1.1 > com.android.tools.build:gradle-core:3.1.1 > com.android.tools.build:builder:3.1.1 > com.android.tools:common:26.1.1
         project : > com.android.tools.build:gradle:3.1.1 > com.android.tools.build:gradle-core:3.1.1 > com.android.tools.build:builder:3.1.1 > com.android.tools.analytics-library:shared:26.1.1
         project : > com.android.tools.build:gradle:3.1.1 > com.android.tools.build:gradle-core:3.1.1 > com.android.tools.build:builder:3.1.1 > com.android.tools.analytics-library:tracker:26.1.1
         project : > com.android.tools.build:gradle:3.1.1 > com.android.tools.build:gradle-core:3.1.1 > com.android.tools.build:builder:3.1.1 > com.android.tools:sdklib:26.1.1 > com.android.tools.layoutlib:layoutlib-api:26.1.1
      > Could not resolve com.android.tools:annotations:26.1.1.
         > Could not parse POM https://dl.google.com/dl/android/maven2/com/android/tools/annotations/26.1.1/annotations-26.1.1.pom
            > Content is not allowed in prolog.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

CONFIGURE FAILED in 34s

prolog 中不允许有内容。

app\build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.kakarot.myapp"
        minSdkVersion 24
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

项目(build.gradle)

// 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我添加了应用模块 build.gradle 和项目 build.gradle。

【问题讨论】:

  • 您的build.gradle 有问题。请附上您的项目build.gradleapp模块build.gradle
  • 感谢您的回复,我已附上您要求的文件
  • 我已经检查并运行了一个项目,将与您的 build.gradle 一样,没有问题。您是否尝试过清理并重建项目?或者你可能在代理后面?
  • 我没有使用代理,重建和清理项目无法从顶部菜单运行,所以我使用“./gradlew clean”命令清理项目,但我仍然遇到同样的错误

标签: android android-gradle-plugin


【解决方案1】:

在 Android Studio 3.0.1 上工作。

如果android studio已经打开,请关闭它,然后删除这些目录的所有内容。

C:\Users\USER_NAME\.gradle\caches
C:\Users\USER_NAME\.android\build-cache
C:\Users\USER_NAME\.android\cache

启动 Android Studio,它可能会工作。第一次加载可能需要一点时间。

【讨论】:

  • 你知道如何在mac上找到这个缓存文件夹吗?
【解决方案2】:

经过一番挣扎和网上搜索,我终于解决了这个问题。

我删除了 gradle 中的所有缓存文件夹以及构建新项目时。它像魔术一样工作。 感谢 @ישו אוהב אותך 的回复并试图帮助我。

【讨论】:

    【解决方案3】:

    我通过删除 .gradle 文件夹中的缓存文件夹解决了这个问题。这是唯一有效的方法(它也适用于 android studio canary)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 2014-06-19
      • 1970-01-01
      • 2011-06-01
      • 2011-07-23
      相关资源
      最近更新 更多