Different lint.xml for different build types in Android Studio?

前端 未结 4 1190
[愿得一人]
[愿得一人] 2021-02-13 13:39

I want to use different lint.xml files for release and debug build types in Android Studio. So, how can this be achieved?

When

4条回答
  •  不思量自难忘°
    2021-02-13 14:14

    I did not try it, but maybe something like this could help you.

    tasks.whenTaskAdded { task ->
        if (task.name == 'lintDebug') {
            task.ext.lintXmlFileName = "lint-debug.xml"
        } else if (task.name == 'lintDemo') {
            task.ext.lintXmlFileName = "lint-demo.xml"
        }
    }
    

    EDIT: comments feedback:

    • task.ext.xxxx is a custom name space for you to use: see https://docs.gradle.org/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html
    • "lintXmlFileName" is a made up name. You won't find doc about it.
    • in android{... lintOptions {... lintConfig file("lint.xml")}} you need to read "lintXmlFileName" using ".ext.get("lintXmlFileName")" and set it for "lintConfig file()"
    • I did not test it, but I assume the "whenTaskAdded" goes outside of "android" in your app's build.gradle.

提交回复
热议问题