Configuration Product Flavors and Build Variants in Android
Note: This is my first English tutorial please there is any mistake please let me know :)
In this tutorial I’ll show build configuration methods for Android Development. Sometime when we development Android Application we have to request different API’s endpoints or we have to use different 3rd API configuration keys or file (google_services.json, Fabric Key etc.) for test server or product servers.
At this scenario we’ll define 2 product flavors;
- QA: provide server url of QA
- Production: provide server url of Production
Now we can define product flavors. First open your build.gradle (app) and define this code in of Android snippet
If you defined above code in Android snippet we can talk about of this code. First select a Build Variant. I selected “QADebug”
What is buildConfigField?
When you select a build variant at Android studio, it creates a build folder in your app’s folder system. It’s name is BuildConfig.java (You can see file place at bottom image)
Did you see similar something at above image? BASE_URL=”http://qa.com/api” . Hımmm i know this line but where did i see? I will help you but first we have to flashback.
When you select QADebug build variant Android Studio builds Build Folder according to your choice. If you selected productionDebug when select a build variant you can see “http://qa.com/api/” instead BASE_URL. And you can call BuildConfig.BASE_URL api URL selected build variant in your project(Retrofit, ION etc.) .
Now you can different create product flavors your project’s steps.
You can read detail information at bottom link.