1

Is that possible allow user to select the server type on runtime before login the application. For example once user install the app, launch the app and display the login screen and then user shake the device 3 times and display the selection screen to select the server type (prod, dev or test env). while selecting the server type and click the save option then it has to select the corresponding server url (either prod, dev or test env.) and again display the login screen (consider user select the test env on selection screen). Finally user has to connect to test env and he has to able to login successfully.

We can implement shake device functionality, no issues in that and my main question is, is that possible to select the server (build flavor) on runtime?

Regards Mindus

AnKr
  • 433
  • 1
  • 6
  • 20

2 Answers2

0

You can not change the build at runtime. but you can check the user selection for showing different UI based on what user has selected prod, dev or test env. But you can change the URL on runtime.

Add all the URLs in gradle.properties Like this

devUrl="YOUR_URL"

prodUrl="YOUR_URL"

Then in app level build.gradle under buildType

  buildTypes {
            release {
                buildConfigField('String', 'DEV_URL', devUrl)
                buildConfigField('String', 'PROD_URL', prodUrl)
            }
            debug {
               buildConfigField('String', 'DEV_URL', devUrl)
                buildConfigField('String', 'PROD_URL', prodUrl)
            }
    }

Then Finally you can use them as

BuildConfig.DEV_URL , BuildConfig.PROD_URL based on user selection .

End User
  • 792
  • 6
  • 14
0

It's not possibile because Android Studio Flavours are something stricted to Compilation time, so before any APK generation. Android Studio Flavours are used to permanently change behaviours, Classes, Resources of resulting APK file.

You need to manually implement all runtime behaviours, Resources and code to handle all possibilities and provide an User way to choose between them in Runtime (obliviously you have to handle this changing procedure).

emandt
  • 2,547
  • 2
  • 16
  • 20