How use buildConfigField to get dependencies version based on build environnement variant?

23 Views Asked by At

I would like to import Android dependencies in the gradle build file and I would like define a version for all my environnement build variant. Then I would like get this version to display it in my aplication.

When use the following code that works :

dependencies {
    evalApi "com.example:test:1.0.7"
    integrationApi "com.example:test:1.0.8"
}

But when I use the following code, that not work, it take already the last version define in the productFlavors (1.0.8):

buildscript {
    ext {
        version = null
    }
}

android {
   flavorDimensions 'environments'
    productFlavors {
        eval {
            version = '0.1.7'
            print("eval - " + version)
        }
        integration {
            version = '0.1.8'
            print("integration - " + version)
        }
    }

    defaultConfig {
        minSdkVersion 28
        buildConfigField "String", "TEST_VERSION", "\"$version\""
    }
}
dependencies {
    print("dependencies - " + version)
    evalApi "com.example:test:$version"
    integrationApi "com.example:test:$version"
}

Console print :

eval - 0.1.7 integration - 0.1.8 dependencies - 0.1.8

But In Eval I would like to be in 0.1.7.

Where is my problem ? How define my version in variable to get in Android application ?

0

There are 0 best solutions below