Gradle-仅执行单个构建类型 [英] Gradle - execute only single build type

查看:111
本文介绍了Gradle-仅执行单个构建类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在build.gradle中定义了多种构建类型.在变体窗口中,我选择了构建变体(例如debugAPI23).我希望只执行一种构建类型的代码.但是在Gradle Console中,我可以看到所有构建类型的输出.

I have multiple build types defined in my build.gradle. In variant window I selected build variant (ex debugAPI23). I expected that code in only one build type will be executed. But in Gradle Console I can see output for all build types.

如您所见,我正在尝试删除每种构建类型的特定文件.但是每次执行所有构建类型时.因此,最后,我缺少了应该为我选择的构建类型提供的文件.

As you can see I am trying to remove specific file for each build type. But everytime all build types are executed. So in the end I am missing the file that should be present for my selected build type.

android {
    buildTypes {
        debug {
            println "build type debug"
            debuggable true
            signingConfig signingConfigs.debug

            sourceSets {
                main.java {
                    exclude '/cz/kctdata/kmf/Reader/KMFReaderCN51A60.java'
                }

                main.java.getIncludes().each { println "Added include: $it" }
                main.java.sourceFiles.each { println "File in source set: " + it }
            }
        }
        release {
            println "build type release"
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            sourceSets {
                main.java {
                    exclude '/cz/kctdata/kmf/Reader/KMFReaderCN51A60.java'
                }

                main.java.getIncludes().each { println "Added include: $it" }
                main.java.sourceFiles.each { println "File in source set: " + it }
            }
        }
        debugAPI23 {
            println "build type debugAPI23"
            debuggable true
            signingConfig signingConfigs.debug

            sourceSets {
                main.java {
                    exclude '/cz/kctdata/kmf/Reader/KMFReaderCN51A42.java'
                }

                main.java.getIncludes().each { println "Added include: $it" }
                main.java.sourceFiles.each { println "File in source set: " + it }
            }
        }
        releaseAPI23 {
            println "build type releaseAPI23"
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

            sourceSets {
                main.java {
                    exclude '/cz/kctdata/kmf/Reader/KMFReaderCN51A42.java'
                }

                main.java.getIncludes().each { println "Added include: $it" }
                main.java.sourceFiles.each { println "File in source set: " + it }
            }
        }
    }
}

我不能使用特定于构建类型的文件夹,因为我有更多的构建类型,并且某些文件应以多种构建类型显示.我不想在我的项目中有相同文件的多个副本.

I can not use build type specific folder because I have more build types and some files should be presented in multiple build types. I don't want to have multiple copies of same file in my project.

推荐答案

最后的gradle android插件具有尺寸"的新概念. https://developer.android.com/studio/build/build-variants. html

Last gradle android plugins have a new concept of "dimensions". https://developer.android.com/studio/build/build-variants.html

因此,您可以尝试使用口味和尺寸.一个例子:

So you can try to use flavors and dimensions. A example:

android {
    flavorDimensions "dim1", "dim2"
}

productFlavors {
    flavor1 {
        dimension "dim1"
    }
    flavor2 {
        dimension "dim1"
    }
    flavor3 {
        dimension "dim1"
    }
    flavor4 {
        dimension "dim2"
    }
}

在这里,您将获得构建类型+带有dim1的青睐+带有dim2的flavor之间的组合,换句话说,flavor4中的文件将可以在所有版本中访问.例如,在变量debugFlavor1Flavor4中,您将拥有属于debug,flavor1和flavor4的所有资源

Here you will get a combination between build type + favor with dim1 + flavor with dim2, in other words files from flavor4 will be accessible in all flavors. For example in variant debugFlavor1Flavor4 you will have all resources which belongs to debug, flavor1 and flavor4

这篇关于Gradle-仅执行单个构建类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆