12

I have a bunch of product flavors defined for my build. However in some scenarios I want to build without a flavor.

However when I try to build a release with no flavor, ie

gradlew assembleRelease

It goes through and builds all of the variants, which takes a really long time. I would like to kick off a release build and ignore all flavors. Is that possible?

I am sure I could add an empty flavor called 'default, and build that. Seems like I should not have to do that.

EDIT:

defaultConfig {
    resValue "string", "hello", "Hello default"
}

productFlavors {
    foo {
        resValue "string", "hello", "Hello Foo"
    }

    bar {
        resValue "string", "hello", "Hello Bar"
    }
}

Seems the answer at the moment is to provide your own 'default' flavor

productFlavors {

    defaults {
       // yup its empty cause I just want to build with the defaults
       // that are already defined.
    }

    foo {
        resValue "string", "hello", "Hello Foo"
    }

    bar {
        resValue "string", "hello", "Hello Bar"
    }
}
lostintranslation
  • 23,756
  • 50
  • 159
  • 262
  • If you added productFlavors, you will have variants now. So your "default" will be `assemble[variant]Debug` and `assemble[variant]Release`. – Jared Burrows Jul 20 '15 at 15:49
  • Yup, I got that. Say I have 2 flavors defined, foo and bar. I know that I can assembleFooRelease and assembleBarRelease. That is not my question. If in that case I do assembleRelease it builds both foo and bar, I do not want that. I want a build with neither flavor. – lostintranslation Jul 20 '15 at 15:51
  • You can't. There is no "default". You have added `productFlavors`. – Jared Burrows Jul 20 '15 at 15:53
  • 3
    I have been looking for a while without an answer, hence this post. IMHO that sucks. Just because I added flavors that provide some different defaults or config shouldn't mean I cannot build without any of them. There is a defaultConfig block where I can define defaults to use without a flavor, seems reasonable to be able to build with just that. Empty flavor it is then.... – lostintranslation Jul 20 '15 at 15:56
  • 1
    You seem to not understand flavors, you can create "default" flavor that only uses your "defaults". The point of flavors is for different installs called variants. See: http://stackoverflow.com/questions/17656826/what-product-flavor-does-android-studio-build-by-default-in-build-gradle#comment31092497_17661238 and http://stackoverflow.com/questions/21307444/gradle-build-only-a-flavour – Jared Burrows Jul 20 '15 at 16:01
  • 3
    How do I not understand? You can override all kinds of things in a flavor.. For instance you can use resValue to provide a resource value. So in my 2 flavors I can define 2 different values for a resource. But I can also put resValue in my defaultConfig block. Meaning that if I want a build with resValue override. I have updated the question to show this. However doesn't matter, apparently you cannot build a non flavor release if you have flavors defined. Still dumb, why have defaults in that case? – lostintranslation Jul 20 '15 at 16:06
  • 1
    The problem is that when Java source files differ between flavors, that file exists only in the flavors, so the plain version would not be complete. Still, it ought to be able to detect that flavors contain only resources and build the default version in that case. – Kevin Krumwiede Dec 16 '15 at 18:31

1 Answers1

0

I found out that "main" as a flavor works. So i dont need to add an additional folder with google-services.json or anything in it

productFlavors {

    main{

    }

    flav1 {
        applicationId 'id'
    }

}
Henning Luther
  • 2,067
  • 15
  • 22
  • 1
    This produces the following error: A problem occurred evaluating root project 'android'. > A problem occurred configuring project ':app'. > Multiple entries with same key: main=[] and main=[] – Schnodderbalken Aug 23 '22 at 14:24