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<File> 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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容