Mastering Product Flavors on Android
The only thing you need to do is define it on each of your products:
android { productFlavors { devel { applicationId "zuul.com.android.devel" } prod { applicationId "zuul.com.android" } } }
Send requests to multiple hosts depending on taste As before, you must include some parameters in the product taste configuration field.
android { productFlavors { devel { applicationId "zuul.com.android.devel" buildConfigField 'String', 'HOST', '"http://192.168.1.34:3000"' } prod { applicationId "zuul.com.android" buildConfigField 'String', 'HOST', '"http://api.zuul.com"' } } }
As an example, we will try to show you how you can integrate this using Retrofit to send a request to the appropriate server without processing the server you are pointing to and based on its taste. In this case, this is an excerpt from the Zuul android application:
public class RetrofitModule { public ZuulService getRestAdapter() { RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(BuildConfig.HOST) .setLogLevel(RestAdapter.LogLevel.FULL) .build(); return restAdapter.create(ZuulService.class); } }
As you can see, you just need to use the BuildConfigclass to access the just defined variable.
source share