Gradle build error: SAXParseException

Gradle build error: SAXParseException

在构建应用程序时,出现以下错误:

Error:org.xml.sax.SAXParseException; lineNumber: 0; columnNumber: 0; 
cvc-pattern-valid: Value 'build-tools;23.0.0 rc3' 
is not facet-valid with respect to pattern '[a-zA-Z0-9_\-;.]+' for type 'segmentListType'.

build.gradle 模块级别 gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "ms.demo.map"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services-maps:8.4.0'
}

即使清理应用程序后错误仍然存​​在。包的结构与 gradle 文件中描述的 applicationId 不匹配。我使用的是最新版本的 Android Studio(2.0 预览版 9)。

错误本身清楚地解释了这里的错误:is not facet-valid with respect to pattern '[a-zA-Z0-9_\-;.]+' for type 'segmentListType'.

只需删除 apply plugin: 'com.android.application' 之前的 space 并重新构建项目。

我在更新到最新的 gradle 后也遇到了这个问题。只需转到 $ANDROID_HOME/build-tools/ 并删除 23.0.0 rc3 目录即可修复错误。

我在更新 android studio 2.0 beta 2 和 gradle 后遇到同样的问题。如需解决方案,请按照以下步骤

  1. 导航到 SDK 路径。
  2. 打开构建工具目录。
  3. 从构建工具目录中删除 23.0.0-preview
  4. build-tools-21.1.2 重命名为 21.1.2

完成。

我使用的是最新版本,并将此 details.useVersion '25.3.0' 更改为

details.useVersion '26.0.0' 

对我有用