B
B
baddev2019-04-17 04:04:46
Android
baddev, 2019-04-17 04:04:46

How does Flavor Dimensions work in Android?

Please help me figure out Flavor Dimensions.
If I understand correctly, this feature allows you to prepare different versions of the same application.
The documentation has this:

flavorDimensions "version"
    productFlavors {
        demo {
            // Assigns this product flavor to the "version" flavor dimension.
            // This property is optional if you are using only one dimension.
            dimension "version"
            applicationIdSuffix ".demo"
            versionNameSuffix "-demo"
        }
        full {
            dimension "version"
            applicationIdSuffix ".full"
            versionNameSuffix "-full"
        }
    }

That is, in the productFlavors section there are two versions of the application (demo and full) - this seems to be understandable. I can't figure out what it is and why flavorDimensions "version".
Here is another example with richer flavorDimensions from the same documentation:
flavorDimensions "api", "mode"

  productFlavors {
    demo {
      // Assigns this product flavor to the "mode" flavor dimension.
      dimension "mode"
      ...
    }

    full {
      dimension "mode"
      ...
    }

    // Configurations in the "api" product flavors override those in "mode"
    // flavors and the defaultConfig block. Gradle determines the priority
    // between flavor dimensions based on the order in which they appear next
    // to the flavorDimensions property above--the first dimension has a higher
    // priority than the second, and so on.
    minApi24 {
      dimension "api"
      minSdkVersion 24
      // To ensure the target device receives the version of the app with
      // the highest compatible API level, assign version codes in increasing
      // value with API level. To learn more about assigning version codes to
      // support app updates and uploading to Google Play, read Multiple APK Support
      versionCode 30000 + android.defaultConfig.versionCode
      versionNameSuffix "-minApi24"
      ...
    }

    minApi23 {
      dimension "api"
      minSdkVersion 23
      versionCode 20000  + android.defaultConfig.versionCode
      versionNameSuffix "-minApi23"
      ...
    }

    minApi21 {
      dimension "api"
      minSdkVersion 21
      versionCode 10000  + android.defaultConfig.versionCode
      versionNameSuffix "-minApi21"
      ...
    }
  }

That is, this is some kind of grouping of application versions, but I can’t understand the meaning, so I’m actually asking for help.
Well, from Habr :
"Suppose you need to create a paid and free application. At the same time, your application is released for TVs, tablets and phones. Moreover, your application is published in different markets."
android {
   flavorDimensions "device", "paid", "market"

   productFlavors {
       tv {
           dimension 'device'
       }
       tablet {
           dimension 'device'
       }
       phone {
           dimension 'device'
       }

       free {
           dimension 'paid'
       }
       premium {
           dimension 'paid'
       }

       google {
           dimension 'market'
       }

       amazon {
           dimension 'market'
       }
   }
}

"By declaring 7 flavors in 3 different groups, you've got 12 different variations of the app."
How did you get 12?
In general, nothing is clear. Thanks in advance to everyone who helps

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AWE64, 2019-05-06
@baddev

How did you get 12?

Roughly speaking, when building an application, you need to select one flavor from each dimension.
We sort through all the options, we get 12
tv free google
tv free amazon
tv premium google
tv premium amazon
tablet free google
tablet free amazon
tablet premium google
tablet premium amazon
phone free google
phone free amazon
phone premium google
phone premium amazon
The point is that in different dimensions you can configure parameters related to logically different aspects of the application. For example, in tv-tablet-phone something about dimensions, navigation, in free-premium something about business logic, in google-amazon something about the libraries used, where links to the market should lead, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question