19

Settings in build.gradle flavorDimensions "xyz", "abc"

@Incubating 
@Deprecated(message = "Replaced by flavorDimensions property") 
public void flavorDimensions(
    @NotNull String... dimensions
)

I could not find an example of a modern approach.

Aldan
  • 674
  • 9
  • 23
David
  • 3,971
  • 1
  • 26
  • 65

4 Answers4

26

Based on the @Deprecated message "Replaced by flavorDimensions property," I replaced my equivalent flavorDimensions "xyz", "abc" instance with:

flavorDimensions = ["xyz", "abc"]

I don't entirely understand the ramifications of this, but it didn't seem to break anything in my admittedly very simple configuration, and the warning went away.

David R. Hedges
  • 421
  • 5
  • 5
  • I suppose that is kotlin dsl and not groovy, right? – David Jan 28 '23 at 09:32
  • 3
    @David You can use `flavorDimensions = ['xyz', 'abc']` in Groovy. – skywall Apr 01 '23 at 20:49
  • 1
    after doing this, gradle sync would run fine, but when i tried to run any of the tests in any other module, i would get the error with the app module with the flavors: `com.android.builder.errors.EvalIssueException: All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html` – Eric Aug 03 '23 at 07:32
  • I think this should be marked as answer. @David if you find his answer helpful and solved, mark it as the answer – Goutham Aug 04 '23 at 21:26
5

Just use:

flavorDimensions += "version"

This works.

TRX
  • 465
  • 1
  • 8
  • 17
  • 1
    Hello. Can you explain more about this? – lgn Aug 17 '23 at 13:53
  • 1
    @lgn https://developer.android.com/build/build-variants#product-flavors This is the official recommended method to configure product flavors now – TRX Aug 22 '23 at 07:20
4

It looks like they change flavorDimensions to accept only List not String, so you need to change the code to look like this:

flavorDimensions = ["dimension"]

Or

flavorDimensions = ["dimension1","dimension2"]
Aldan
  • 674
  • 9
  • 23
Mohamed Ben Romdhane
  • 1,005
  • 3
  • 11
  • 22
0

after updating my build.gradle file to using flavorDimensions ["dimension1","dimension2"], i got an error while building:

A problem occurred configuring project ':app'.
> com.android.builder.errors.EvalIssueException: All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

to fix this, i had to do this instead:

flavorDimensions.add("dimension1")
flavorDimensions.add("dimension2")

related: https://stackoverflow.com/a/68661161/2898715

Eric
  • 16,397
  • 8
  • 68
  • 76