Home > Mobile >  Active Build Variant - Gradle - Library Imlementation
Active Build Variant - Gradle - Library Imlementation

Time:08-15

I have three build variants. pentest, release, uat

There are two libraries that are duplicates of each other.

'com.demirci:security:1.0.1' 
'com.demirci:security-pentest:1.0.1'

Que : While the Pentest build variant is active, the library 'com.demirci:security-pentest:1.0.1' needs to be implemented. Otherwise, 'com.bank:security:1.0.1' needs to be added in the other two variants(release, uat).

The code I wrote below is working.

pentestImplemantation 'com.demirci:security-pentest:1.0.1'
uatImplemantation 'com.demirci:security:1.0.1'
releaseImplemantation 'com.demirci:security:1.0.1'

but i want to improve it. If the active build variant text contains the word "pentest", add the library 'com.demirci:security-pentest:1.0.1', otherwise I want to add something like add another.

How can I do that? Can you help me?

CodePudding user response:

I found the solution. I hope it will be useful to others

applicationVariants.all { variant ->
    def currentVariantImplementation = variant.getName()   "Implementation"
    if (variant.getName().contains('pentest')) {
        dependencies."$currentVariantImplementation" 'com.demirci:security-pentest:1.0.1'
    } else {
        dependencies."$currentVariantImplementation" 'com.demirci:security:1.0.1'
    }
}
  • Related