AndroidStudio 构建出错“ERROR: The SourceSet 'lintOptions' is not recognized by the Android Gradle Plu...

android {

    [...]

    lintOptions {
        abortOnError false
        checkReleaseBuilds  false
    }

    [...]

}

以上是gradle中lint的相关配置,点击sync 进行同步时,出现标题的错误。在stackoverflow查找了相关问题后,找到以下答案:

  • 答案一:

将gradle配置改成以下:

model {
    android {

        [...]

        lintOptions.abortOnError false   //只需要把lint配置改成这样即可

        [...]
    }
}

经测试,这个方法是有效的。

  • 答案二:

将gradle配置改成如下:

model {
    android.lintOptions {
        abortOnError false
    }

    android {
        // Rest of the other declarations goes here...
    }
}

此答案与一类似,gradle的配置多了一个model外层,回答者也给了一个gradle变更的链接。打开链接可以发现以下变更:

NOTE: There has been significant DSL improvements starting from version 0.6.0-alpha5 compare to previous versions. The example code here will not work for previous version. If you are using an older version of the plugin. Please refer to the user guide at https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/gradle-experimental/0-4-0.

DSL Changes:

  • Plugin name is com.android.model.application instead of com.android.application. Or use apply plugin: "com.android.model.library" if you want to create an Android aar library.
  • Configuration is wrapped with the model { } block
  • Adding elements to a Collection should be done using the add method.

Gradle变更资料链接
从以上可以知道,gradle配置用了一个model{}进行包装,而lintOptions等配置引用则更改为android.lintOptions。

DSL Change
The plugin is still in experimental stage. DSL will change throughout the development of the plugin. This section documents the changes that occurs between different versions to help with migration.

0.6.0-alpha1 -> 0.6.0-alpha5

  • Plugin now requires Gradle 2.10, which brings significant improvements to DSL
  • Configurations can now be nested. E.g. you can write
    android {
    buildTypes {
    ...
    }
    }
    instead of:
    android.buildTypes {
    ...
    }
  • File type now accepts a string, but String cannot be added to List at the moment.
  • -Dorg.gradle.model=true is now the default. This allows references to other model, but the model being referred to must be in a separate block.
  • The equal sign '=' is no longer required for most properties.

参考答案链接:lintOptions not being recognized by Gradle

你可能感兴趣的:(AndroidStudio 构建出错“ERROR: The SourceSet 'lintOptions' is not recognized by the Android Gradle Plu...)