Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create different build variants pointing to different Servers?

Tags:

android

gradle

I am using gradle.build for auto building my app. I want to generate three different APK's each pointing to different Service URL's.

How can I make use of buildVariants (productFlavors in gradle). But I'm not able to figure out where to set the three URL's in the Gradle.

How can I do this?

like image 557
Jainendra Avatar asked Mar 15 '23 16:03

Jainendra


1 Answers

It is really easy to do with gradle.

productFlavors {
    first_server {
        buildConfigField "String", "SERVER_URL", "\"https://first_server_url/\""
    }
    second_server {
        buildConfigField "String", "SERVER_URL", "\"https://second_server_url/\""
    }
}

You may want to find more information here.

So later you can easy access this variable by BuildConfig.SERVER_URL

like image 81
Anatol Avatar answered Mar 21 '23 14:03

Anatol