Dynamic Gradle compile dependencies for different buildConfigFields

In my project I am using different configurations based on different buildConfigFields and for some of them I am not using specific dependencies. So I don't want to have certain dependencies in certain configurations, depending on buildConfigFields.

How can I do something similar to the following?

dependencies {
    if (buildConfigField("String", "WHICH_MESSAGE_ENABLED") == "VALUE") {
        compile "xxx.yyy.zz:1.0"
    } else {
        provided "xxx.yyy.zz:1.0"
    }
}

      

+3


source to share


1 answer


You can use the following in defaultConfig:

def mBuildConfigFields

android {
    defaultConfig {
        mBuildConfigFields = buildConfigFields
    }
}

dependencies {
    if (localBuildConfigFields.get("KEY").value == "VALUE") {
        compile "xxx.yyy.zz:1.0"
    } else {
        provided "xxx.yyy.zz:1.0"
    }
}

      



Hope it helps.

0


source







All Articles