{"id":15374,"date":"2014-09-02T10:54:44","date_gmt":"2014-09-02T05:24:44","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=15374"},"modified":"2014-09-02T11:22:22","modified_gmt":"2014-09-02T05:52:22","slug":"building-android-application-with-different-productflavors","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/building-android-application-with-different-productflavors\/","title":{"rendered":"Building Android Application with different productFlavors"},"content":{"rendered":"<p>Applications are developed using some arbitrary values for development and QA. But, when it comes to production or releasing a new update for app, we need to change those arbitrary values to actual values.<\/p>\n<p>For instance, take an application using web services, which requires some input from user and store it in database. During development and testing, many valid but arbitrary values are provided. And, we don&#8217;t want those values inside production database. So, an option is to keep different URL for different purposes.<\/p>\n<p>But, there is another problem. We need to update our application (web service url) each time we create a build for development, QA and production.<\/p>\n<p>For this type of problem <kbd>productFlavors<\/kbd> comes to our rescue.<\/p>\n<p>In Android Studio project, open <kbd>build.gradle<\/kbd> of the module.<\/p>\n<p>[code]&lt;project-name&gt;\/&lt;module-name&gt;\/build.gradle[\/code]<\/p>\n<p>In it, inside <kbd>android<\/kbd> block, add <kbd>productFlavors<\/kbd>.<\/p>\n<p>[code]android {<br \/>\n&#8230;<\/p>\n<p>    productFlavors {<\/p>\n<p>        Development {<\/p>\n<p>        }<\/p>\n<p>        QA {<\/p>\n<p>        }<\/p>\n<p>        Production {<\/p>\n<p>        }<\/p>\n<p>    }<\/p>\n<p>}[\/code]<\/p>\n<p>Now, create three directories inside<br \/>\n[code]&lt;project-name&gt;\/&lt;module-name&gt;\/src\/Development<br \/>\n&lt;project-name&gt;\/&lt;module-name&gt;\/src\/QA<br \/>\n&lt;project-name&gt;\/&lt;module-name&gt;\/src\/Production[\/code]<\/p>\n<p>Based on the requirements, create <kbd>java<\/kbd> and <kbd>res<\/kbd> directories inside all three. If you don&#8217;t need any resource specific to the flavors then skip creating <kbd>res<\/kbd>.<\/p>\n<p>Now, create package inside each <kbd>java<\/kbd> and keep the java code there which are specific to that flavor.<\/p>\n<p>I have uploaded a demo application project on GitHub <a href=\"https:\/\/github.com\/navkrishna\/FlavourUsage\/\" target=\"_blank\">FlavourUsage<\/a>. Clone, fork, modify and create your own flavor specific application.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Applications are developed using some arbitrary values for development and QA. But, when it comes to production or releasing a new update for app, we need to change those arbitrary values to actual values. For instance, take an application using web services, which requires some input from user and store it in database. During development [&hellip;]<\/p>\n","protected":false},"author":133,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[518],"tags":[4845,1503,1502],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15374"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/133"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=15374"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15374\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=15374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=15374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=15374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}