Exclude specific build variants

后端 未结 9 910
一向
一向 2020-12-07 11:07

I have the two default build types: debug / release and a couple of flavors: prod / dev.

Now I want to exclude the build variant dev-release, but keep all other poss

9条回答
  •  日久生厌
    2020-12-07 11:27

    Using variant filters like others I found it was easiest to do this by comparing the variant name against a list of variants that I want to keep.

    So in my app/build.gradle file I have something like:

    android {
        variantFilter { variant ->
            def needed = variant.name in [
                    'stagingQuickDebug',       // for development
                    'stagingFullDebug',        // for debugging all configurations
                    'stagingFullCandidate',    // for local builds before beta release
                    'stagingFullRelease',      // for beta releases
                    'productionFullCandidate', // for local builds before going public
                    'productionFullRelease'    // for public releases
            ]
            variant.setIgnore(!needed)
        }
        buildTypes {
            debug {
            }
            release {
            }
            candidate.initWith(release)
        }
        flavorDimensions "server", "build"
        productFlavors {
            staging {
                dimension "server"
                buildConfigField "String", "API_URL", '"https://example-preprod.com/"'
            }
            production {
                dimension "server"
                buildConfigField "String", "API_URL", '"https://example.com/"'
            }
            quick {
                dimension "build"
                minSdkVersion 21
                resConfigs("en", "xxhdpi")
            }
            full {
                dimension "build"
            }
        }
    }
    

提交回复
热议问题