Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android specific flavor dependency via Kotlin DSL

Inside build.gradle we could

   productFlavors {
        free {
            dimension "tier"
        }
    }

Then

dependencies { freeDebugImplementation "com.someDependency:free-debug:1.0.0";}

BUT when I use Kotlin DSL, inside build.gradle.kts, I

productFlavors { create("free") {...} }

Then in dependencies I can not

dependencies { freeImplementation(...)}

Error: ^ Unresolved reference: freeImplementation So, how can I implementation for specific flavor via Kotlin DSL?

like image 842
Neil G Avatar asked Jan 10 '20 06:01

Neil G


People also ask

What is missingDimensionStrategy?

void missingDimensionStrategy ( String dimension, String requestedValue) Specifies a flavor that the plugin should try to use from a given dimension in a dependency. Android plugin 3.0. 0 and higher try to match each variant of your module with the same one from its dependencies.

What is Productflavors Android?

Product Flavors so what are they? Simply put, a product flavor is a variant of your app. It is very useful when you want to create multiple versions of your app. This means you can generate different versions or variants of your app using a single codebase.

What is flavorDimensions?

Flavor Dimensions is a way to group flavors by a name. For now, we're using just a single group. Add the following line in your defaultConfig block: flavorDimensions "default" Now syncing the gradle would give you the following product flavors: Android Build Variants combine build types and product flavors.

How do I get the current flavor in gradle?

gradle. getStartParameter(). getTaskRequests(). toString() contains your current flavor name but the first character is capital.


2 Answers

I Kotlin DSL flavor specific dependency looks like this:

dependencies { 
    "freeImplementation"(...)
    "paidImplementation"(...)

}
like image 55
Francis Avatar answered Oct 18 '22 00:10

Francis


You should use the sample "YOUR_FLAVOR_NAMEimplementation"

dependencies {

    "freeImplementation" "your dependency is here"
    "paidImplementation" "your dependency is here"
    // Other dependencies    

}

like image 45
Alexander Avatar answered Oct 18 '22 00:10

Alexander