Search code examples
androidgradle

Set contants different for Production and Development


When we create apk file or run app, we have to check if the app url is set to production or development server.

That's why sometimes we forget to update it and provide wrong app to user.

I want a way to set such constants as per the debug / release type of gradle.

Any information is welcomed Thanks!!


Solution

  • The following code sample creates a flavor dimension named. Please check this document

    flavorDimensions += "AppName"
    
    productFlavors {
        create("development") {
            dimension = "AppName"
            buildConfigField("String", "BASE_URL", "Your url")
            buildConfigField("String", "BASE_API_URL", "Your url")
            buildConfigField("String", "BASE_SOCKET_URL", "Your url")
        }
        create("production") {
            dimension = "AppName"
            buildConfigField("String", "BASE_URL", "Your url")
            buildConfigField("String", "BASE_API_URL", "Your url")
            buildConfigField("String", "BASE_SOCKET_URL", "Your url")
        }
    }