android - Gradle 构建期间序言中不允许出现内容

标签 android android-gradle-plugin

我尝试了不同的方法,但问题没有解决,我什至重新安装了 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

序言中不允许出现内容。

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。

最佳答案

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

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

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

关于android - Gradle 构建期间序言中不允许出现内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49825507/

相关文章:

java - 在应用程序模块中使用库模块的依赖项

android - 如何在android studio中解析 "error: cannot find symbol variable new_location"?

android - 如何并行运行独立的 Robotium UI 测试?

android - 如何在 React Native 中创建 Android 即时应用程序?

适用于所有 SDK 的 Android Google Analytics v2 广播接收器

Android计算Canvas中两点之间的长度或距离

android - 根据 build.gradle 中的风格传递参数

java - fragment 对话框动画正确但布局完全黑色

android - menu.addIntentOptions() 的正确用法是什么?

unit-testing - 为什么 Android Studio 会说 "Test events were not received"?