How do I create different build variants pointing to different servers?
2 answers
It's really easy to do this with gradle.
productFlavors {
first_server {
buildConfigField "String", "SERVER_URL", "\"https://first_server_url/\""
}
second_server {
buildConfigField "String", "SERVER_URL", "\"https://second_server_url/\""
}
}
You can find more information here .
So, you can easily access this variable with BuildConfig.SERVER_URL
+4
source to share
You can use as shown below,
In Gradle:
productFlavors{
serverone {
applicationId "com.example.krishna.mysample.serverone"
version 1.1
}
servertwo {
applicationId "com.example.krishna.mysample.servertwo"
version 1.1
}
serverthree {
applicationId "com.example.krishna.mysample.serverthree"
version 1.1
}
}
In the folder structure in the application:
src -->main -->serverone -->servertwo -->serverthree
If different logic
MainActivity is required then MainActivity is only placed in serverone, servertwo and serverthree folder remaining classes are keep in main folder
. And perform various functions in this activity.
+3
source to share