Skip to content Skip to sidebar Skip to footer

Android Tests Buildconfig Field

Suppose my build.gradle file defines different values for the same variable that is defined in BuildConfig: android { def INTEGER= 'integer' def VARIABLE = 'variable' b

Solution 1:

I found a way to do this here

Create another buildType (whose name must not start with: test) and pass it's name to property:

android {

    testBuildType "staging"

    def INTEGER= "integer"
    def VARIABLE = "variable"
    buildTypes {

        debug {
            buildConfigField BOOLEAN, VARIABLE, "2"
        }

        staging {
            initWith(buildTypes.debug)
            buildConfigField BOOLEAN, VARIABLE, "4"
        }
    }
}

Tests must be run against stagingbuildType.

Solution 2:

The Kotlin DSL equivalent of the above solution would be this:

android {
  buildTypes {
    create("local") {
      initWith(buildTypes["debug"])
      buildConfigField("Boolean", "IS_CI", "${System.getenv("CI") == "true"}")
      isDebuggable = true
    }
    testBuildType = "local"
  }
}

Post a Comment for "Android Tests Buildconfig Field"