<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anusree Sajeevan on Medium]]></title>
        <description><![CDATA[Stories by Anusree Sajeevan on Medium]]></description>
        <link>https://medium.com/@anusreesajeevan111?source=rss-9c6812153073------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*n2PWJbvXCfu2VvAuftWCCg.jpeg</url>
            <title>Stories by Anusree Sajeevan on Medium</title>
            <link>https://medium.com/@anusreesajeevan111?source=rss-9c6812153073------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:16:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anusreesajeevan111/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create an Android Library  (AAR)]]></title>
            <link>https://proandroiddev.com/create-an-android-library-aar-79d2338678ba?source=rss-9c6812153073------2</link>
            <guid isPermaLink="false">https://medium.com/p/79d2338678ba</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android-libraries]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Anusree Sajeevan]]></dc:creator>
            <pubDate>Tue, 12 Oct 2021 15:25:01 GMT</pubDate>
            <atom:updated>2021-10-13T10:51:29.814Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create an Android Library (AAR)</h3><h4>Steps to create an Android library, blockers while creating it and how to resolve them</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RJgV3AUo0ZK8FTIL" /><figcaption>Photo by <a href="https://unsplash.com/@inakihxz?utm_source=medium&amp;utm_medium=referral">Iñaki del Olmo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As an Android developer, you should have used a lot of libraries in your apps. An Android library, also called as Android Archive, includes everything you need to build an app like source files, resource files, manifest etc. This is the reason why AARs are different from JARs. AARs can contain resource files as well other than compiled byte code. You can create your own Android library which can be used in multiple apps.</p><p>In this blog, we’re going to see how to create an Android library, some of the blockers while creating it and how to resolve them. You can learn more about libraries here in the <a href="https://developer.android.com/studio/projects/android-library">official documentation</a>.</p><p>You can either create a new library module or convert the existing module as library module.</p><p><strong>Below are the steps to create a new library module:</strong></p><ol><li>Go to File -&gt; New Module</li><li>Select Android Library and provide the details</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcX8-fZuymT9j10o5pETiw.png" /></figure><p>3. Click on Finish. A new module with the given module name will be created. It’ll have the same structure as any other modules. You can add resource files and add your logic to the library module which has been created.</p><p>If you go to the module level build.gradle file of the newly added library module, you won’t be able to see the <em>applicationId</em> element in it. Since only application modules can define applicationId.</p><p>Also you’ll see the plugin for Android library as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f19bddd34e5852b50191749e36ae1732/href">https://medium.com/media/f19bddd34e5852b50191749e36ae1732/href</a></iframe><p>You can even convert an existing app module to a library module, if you already have one.</p><p><strong>Below are the steps to convert app module to library module:</strong></p><ol><li>Open module level build.gradle file</li><li>Remove applicationId element</li><li>Replace plugin<em> id ‘com.android.application’ </em>with<em> id ‘</em>com.android.library’</li><li>Sync project with Gradle files</li></ol><p>You’re done! The structure of your module remains the same but when you build it, an AAR will be created instead of an APK.</p><p>Now you’ve a library module created. It’s time to create an AAR file out of it. To do that, you can execute the <em>build</em> task of Gradle.</p><p>A task is a piece of work performed by a build. It can be building a JAR or AAR, compile a class etc. Each project is made up of different tasks. you can see the list of tasks either by executing the command:</p><pre>./gradlew task</pre><p>Once you get list of available tasks, you can execute it using the following command:</p><pre>./gradlew &lt;taskname&gt;</pre><p>To build an AAR, you can use the command,</p><pre>./gradlew build</pre><p>Your AAR file will be created!</p><p>If you’re not using Gradle command line tools, you can build an AAR using the Gradle navigation tab option within Android Studio. You can open the Gradle tab <em>by pressing shift button twice </em>while you’re in Android Studio.</p><p>In the Gradle tab, open our library module -&gt; tasks -&gt; build.</p><p>One issue I faced while creating an AAR was that the tasks option was not showing under library module in the Gradle tab as shown below. The version used was <em>Android Studio Bumblebee | 2021.1.1 Canary 12.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*ZQ2PuRjhRpPrBTdFZ5hDXQ.png" /></figure><p>This is an experimental change introduced in Android Studio where the Gradle tasks won’t build during Gradle sync. To resolve this issue, <strong>disable the following experimental setup in settings</strong>.</p><p>File -&gt; Settings -&gt; Preferences -&gt; Experimental -&gt; do not build Gradle task list during Gradle sync. And then do a project sync.</p><p>File -&gt; Sync Project with Gradle Files.</p><p>You’re done. Now you should be able to see tasks under your library module as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*dGlil56l-RFqYt-j_Bormg.png" /></figure><p>Now, go ahead and build your AAR 🎊</p><p><em>Thanks for reading! Share your thoughts and experience in the comments. Let’s learn together !!</em></p><p><em>Happy learning and happy coding :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79d2338678ba" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/create-an-android-library-aar-79d2338678ba">Create an Android Library  (AAR)</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SplashScreen API — Android 12 (Part 1)]]></title>
            <link>https://proandroiddev.com/splashscreen-api-android-12-part-1-b2272e0ae98e?source=rss-9c6812153073------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2272e0ae98e</guid>
            <category><![CDATA[android-12]]></category>
            <category><![CDATA[splash-screen]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Anusree Sajeevan]]></dc:creator>
            <pubDate>Fri, 08 Oct 2021 14:20:38 GMT</pubDate>
            <atom:updated>2021-10-13T11:59:16.632Z</atom:updated>
            <content:encoded><![CDATA[<h3>SplashScreen API — Android 12 (Part 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u15-H9QsGhkcdvEA" /><figcaption>Photo by <a href="https://unsplash.com/@thenata?utm_source=medium&amp;utm_medium=referral">Anastasia Taioglou</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Splash screen is the initial screen you’ll see when you open your app. It also called as launch screen or start up screen. The duration at which system will show your splash screen and it’s performance depends on factors like app startup time. It may vary depending upon whether your app process is already running in the system or not. You can understand more about app startup time in the official documentation <a href="https://developer.android.com/topic/performance/vitals/launch-time">here</a>.</p><p>In order to customise splash screen by adding a logo, for example, usually you would need to create a new activity, create a layout to specify your logo, set background, theme for the splash screen etc. But Android makes it a lot easier in version 12 and above.</p><p>If you’re not creating an activity to customise your splash screen, then by default, splash screen uses <em>android:windowBackground attribute</em> of your app theme where you can specify a single solid colour for the splash screen background.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05435e3fe3af110e756da9fa72b97043/href">https://medium.com/media/05435e3fe3af110e756da9fa72b97043/href</a></iframe><p>Splash screen background will be white colour as specified and will look like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k7lcXYeKr-y0208vqEbD3A.gif" /></figure><p>Android 12 introduced a new <strong>SplashScreen API</strong>. With this API, you don’t need to create a separate activity to customise the splash screen. The system will automatically create one for you. It also allows you to have a new launch animation for your apps. The look and feel of splash screen in devices having Android 12 or higher is different from the look of splash screens in lower versions.</p><p>To create a splash screen, you can either directly use the SplashScreen API or use <a href="https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen">AndroidX Splash screen compat library</a>. But the recommendation is to use the support library. If you’re not using support library, your splash screen will exactly have the same old look in lower versions as you had before. But with AndroidX compat library, the splash screen looks consistent across all the devices with various android versions. Even in the devices having version less than 12.</p><blockquote>Knowledge is of no value unless you put it into practice — Anton Chekhov</blockquote><p>Following are the steps to migrate to SplashScreen API or start using it in your apps:</p><ol><li>Change compileSdk to 31 in the module level <em>build.gradle file</em> and add SplashScreen API compat library dependency</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b8bb341907ebcc6ca197ca54e75e089/href">https://medium.com/media/0b8bb341907ebcc6ca197ca54e75e089/href</a></iframe><p>2. Create a <em>custom theme</em> whose parent is <em>Theme.SplashScreen.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/249f129e2a34469fb78ab78e7c07f08d/href">https://medium.com/media/249f129e2a34469fb78ab78e7c07f08d/href</a></iframe><p><em>Theme.CustomSplashScreenTheme</em> is the new theme we created for the splash screen.</p><p>The <em>android:windowSplashScreenBackground</em> is a replacement for windowBackground in higher versions. Which specifies solid colour for window background.</p><p>If you’re not using support library of splash screen, replace windowBackground with windowSplashScreenBackground for versions above 12. It is added in <em>API level 31</em>. So it requires API level 31. So the system will notify you of the same <em>i</em>f your current minSdk version is less than 31. Then override themes.xml for version 31 and specify android:windowSplashScreenBackground to specify background colour.</p><p><em>android:windowSplashScreenAnimatedIcon</em> specifies the static or animated drawable. <em>android: windowSplashScreenAnimationDuration</em> needs to be mentioned for the drawable which is animated. This specifies how long the animation should be shown on the screen. The recommended duration for app icon animation is that it shouldn’t exceed 1000 milliseconds.</p><p><em>android:postSplashScreenTheme</em> specifies the theme of the activity that follows the splash screen immediately. It’ll be the theme of your home screen.</p><p>3. In the <em>manifest.xml file</em>, add application theme to the newly created Custom theme.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96ce47666fbcf3f4f2afef46726067f3/href">https://medium.com/media/96ce47666fbcf3f4f2afef46726067f3/href</a></iframe><p>4. To use the splash screen features, call <em>installSplashScreen() method </em>before setContentView() within the activity which starts immediately after the splash screen. In our case, it is MainActivity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbb47235d3d5409c88c8808a22c4ec9a/href">https://medium.com/media/fbb47235d3d5409c88c8808a22c4ec9a/href</a></iframe><p><em>installSplashScreen</em> will create an instance of Splash screen and return it. It also set the postSplashScreenTheme to the MainActivity . If you’re not creating your custom theme and not specifying postSplashScreenTheme, then you’ll get an error like this:</p><p>Caused by: android.content.res.Resources$NotFoundException: Cannot set AppTheme. No theme value defined for attribute com.anu.talesofknots:attr/postSplashScreenTheme</p><p>postSplashScreenTheme is similar to setting theme to Activity using Activity.setTheme().</p><p>5. Build and Run the app to see the changes..</p><p>Tadaaa !!</p><p>Your new splash screen is now ready.</p><p>With SplashScreen support library, this is how our splash screen looks like. It will be similar in all android versions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iADAfyTmAGeNSIp0nCFkZQ.gif" /></figure><p>Splash screen is like any other screen in app so that you can associate your branding to splash screen as well and it goes well with your app’s overall design. We’ll discuss more about customising splash screen in upcoming blogs.</p><p><em>Thanks for reading! Share your thoughts and experience in the comments. Let’s learn together !!</em></p><p><em>Happy learning and happy coding! :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2272e0ae98e" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/splashscreen-api-android-12-part-1-b2272e0ae98e">SplashScreen API — Android 12 (Part 1)</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Product flavour/Flavour Dimensions in Android — How to customize your app?]]></title>
            <link>https://proandroiddev.com/product-flavour-flavour-dimensions-in-android-how-to-customize-your-app-395c17b0ff9b?source=rss-9c6812153073------2</link>
            <guid isPermaLink="false">https://medium.com/p/395c17b0ff9b</guid>
            <category><![CDATA[customization]]></category>
            <category><![CDATA[build-variants]]></category>
            <category><![CDATA[android-build-variant]]></category>
            <category><![CDATA[productflavor]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Anusree Sajeevan]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 15:02:24 GMT</pubDate>
            <atom:updated>2021-09-26T15:02:24.701Z</atom:updated>
            <content:encoded><![CDATA[<h3>Product flavour/Flavour Dimensions in Android — How to customize your app?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Qt8XKtfshctDKNVlY1vjkA.jpeg" /></figure><p>You are developing an android application and there can be different scenarios when you would like to customise the existing app with some small changes. The below are the scenarios that you might come across in customising your app.</p><p><strong>Scenario 1 : </strong>You are developing an android application which is having it’s own colours, styles, logo etc. Suppose you want to have the same app with a different style, colours, logo etc.</p><p><strong>Scenario 2 : </strong>You would like to customise the URL which your app is pointing. In that case, only the end point changes but the core app features remains the same.</p><p><strong>Scenario 3 : </strong>You would like to have two apps with same core functionalities, but a few features you want to show only in one of the app and hide those in the other one.</p><p><strong>Scenario 4:</strong> You would like to white label your app.</p><blockquote>White labelling in Android simply means taking an existing app and rebranding it or customising it by changing the app’s icon, theme, styles, name, APIs, etc.</blockquote><p>If you are in these kind of situations, the quick thing that might come to your mind is to maintain a separate codebase for both variants of the app. But there can be some technical difficulties to maintaining different codebases. When there is a change in the code, we would need to do the same change in both the codebases, and this might be a tedious process when the codebase is too large. So maintaining different codebases might not be a good approach in such a situation.</p><p>You can achieve these scenarios by using product flavours or flavour dimensions feature in android.</p><h3>Basics</h3><p>Android by default having two build types, debug and release. You are able to find these in build variants option, which you will be able to achieve in the bottom left corner of the android studio. Or simply you can press the shift button twice and search for build variants, the section will automatically opens for you.</p><figure><img alt="Build variants section in android studio" src="https://cdn-images-1.medium.com/max/540/0*45NbmY28pOnAsBMs.png" /></figure><p>Addition of new build type can be done in the module level build.gradle file.</p><pre>buildTypes {<br>    debug {<br>       minifyEnabled false<br>       debuggable true<br>    }<br>    qa {<br>       minifyEnabled true<br>       debuggable false<br>    }<br>    release {<br>       minifyEnabled true<br>       debuggable false<br>       proguardFiles getDefaultProguardFile(‘proguard-android-  optimize.txt’), ‘proguard-rules.pro’<br>    }<br>}</pre><p>We have added 3 build types here : debug, qa and release. Now you can see these three build types in the build variants section.</p><figure><img alt="Build variants section after adding build variant" src="https://cdn-images-1.medium.com/max/541/0*u_BMWX3nnuS_XRax.png" /></figure><p>You can select which build variant you want and and then install the app from android studio by clicking on the ‘Run’ button.</p><p>Now the app it will looks like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*0GRaPmhM43kmkqYB.png" /></figure><h3>What is Product Flavours?</h3><p>In simple words — <em>Consider you’re preparing pizzas. You use same core ingredients to make the base but will use different toppings for each one to have a different taste. Similarly, android apps can have the same base functionalities with changes to some of the features like styles, logo etc. This can be achieved using product flavours.</em></p><p>Product flavours lets you create multiple variants of an android app while using a single codebase.</p><p>To create product flavours you need to define rules in the <strong>build.gradle </strong>which you’ll learn shortly.</p><h3>Steps to create product flavours</h3><p>Now consider you need to have the same app in two different colours say red and green. Let’s see how we can proceed by creating product flavours and here are the steps.</p><p><strong>Step 1 : Add product flavours in the build.gradle file</strong></p><p>Customize app level build.gradle by adding product flavours for red and green colours in the <strong>productFlavors</strong> section.</p><pre>flavorDimensions &#39;default&#39;<br>productFlavors <strong>{<br>    </strong>redFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>    <strong>}<br>    </strong>greenFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>    <strong>}<br>}</strong></pre><p>Here, redFlavor is for the app variant with red color and greenFlavor is for app with green color.</p><p><strong>Navigate to build variants -&gt; </strong>Now when you navigate to build variants section, you should be able to see build variants for both of these flavours as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*RiVwF7RFWsj_G_kk.png" /></figure><p><strong>Install App -&gt;</strong> If you select any of the variant in build variants section and install app, you will be still able to see the app with the default colour as shown above.</p><p>So, the next thing is to see how to change the colour in different variants of app. Following are the steps to do that.</p><p><strong>Step 2 : Create resource folder for the flavours created</strong></p><p>Separate resource folder should be created for each of the variants where the colour should be specified. Create a res folder navigating to <strong>app -&gt;New -&gt; Folder -&gt; Res Folder</strong></p><p>You should be able to select the build variant for which you want to create the resource folder. Select the flavour and click finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*zFi5P1CCzg6Tde2r.png" /></figure><p>Now a resource folder named <strong>res</strong> will be created inside <strong>src</strong> folder for the greenFlavor, since the greenFlavor is selected.</p><p><strong>Step 3 : Create colors.xml for the variant</strong></p><p>Now you can create colors.xml in the newly created folder under the location <strong>app -&gt; src -&gt; greenFlavor -&gt; res -&gt; values</strong></p><p><strong>Step 4 :</strong> <strong>Change colors, styles, logos etc</strong></p><p>Now you need to add green colour in the res folder for the green flavor. For that, change primary and secondary colors in the new colors.xml file.</p><p><strong>Select the greenFlavor build variant and install the application -&gt;</strong></p><p>You should be able to see the colour of the toolbar changed to green.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*VEyFjVSk7I1gRvCL.png" /></figure><p>This way you should be able to customize the resources for each build flavour including styles, colors, themes, logos and even more.</p><h3>Project config properties</h3><p>There are various project config properties which can be specified for the product flavours. Some of them are minSdkVersion, targetSdkVersion, versionName, versionCode and many more.</p><p>In the example below, you can see the minimum and maximum sdk versions are configured. You can also customise the values for the variants using buildConfigField and one such use case is to customise the host url for the application for each variants. The specified values can be accessed by <strong>BuildConfig.HOST_URL </strong>in this example.</p><pre>flavorDimensions &#39;default&#39;<br>productFlavors <strong>{<br>    </strong>redFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>        applicationId &quot;com.sample.productFlavors&quot;<br>        minSdkVersion 15<br>        targetSdkVersion 28<br>        buildConfigField &quot;String&quot;, &quot;HOST_URL&quot;, &quot;\&quot;host url 1\&quot;&quot;<br>    <strong>}<br>    </strong>greenFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>        applicationId &quot;com.sample.productFlavors&quot;<br>        minSdkVersion 18<br>        targetSdkVersion 28<br>        buildConfigField &quot;String&quot;, &quot;HOST_URL&quot;, &quot;\&quot;host url 2\&quot;&quot;<br>    <strong>}<br>}</strong></pre><p>Now this is time to explore more…</p><p><strong>Happy learning &amp; Happy coding :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=395c17b0ff9b" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/product-flavour-flavour-dimensions-in-android-how-to-customize-your-app-395c17b0ff9b">Product flavour/Flavour Dimensions in Android — How to customize your app?</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understand Product flavour/Flavour Dimensions in Android — How to customize your app?]]></title>
            <link>https://medium.com/@anusreesajeevan111/understand-product-flavour-flavour-dimensions-in-android-how-to-customize-your-app-426529d78cce?source=rss-9c6812153073------2</link>
            <guid isPermaLink="false">https://medium.com/p/426529d78cce</guid>
            <category><![CDATA[white-label-android-app]]></category>
            <category><![CDATA[productflavor]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[multiplebuildtypes]]></category>
            <category><![CDATA[customise-android-apps]]></category>
            <dc:creator><![CDATA[Anusree Sajeevan]]></dc:creator>
            <pubDate>Fri, 18 Sep 2020 16:58:49 GMT</pubDate>
            <atom:updated>2020-09-18T17:29:36.447Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Product flavour/Flavour Dimensions in Android — How to customize your app?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_aYAYqCGI4NQI0AP07MZSA.jpeg" /></figure><p>You are developing an android application and there can be different scenarios when you would like to customise the existing app with some small changes. The below are the scenarios that you might come across in customising your app.</p><p><strong>Scenario 1 : </strong>You are developing an android application which is having it’s own colours, styles, logo etc. Suppose you want to have the same app with a different style, colours, logo etc.</p><p><strong>Scenario 2 : </strong>You would like to customise the URL which your app is pointing, in that case only the end point changes, but the core app features remains the same.</p><p><strong>Scenario 3 : </strong>You would like to have two apps with same core functionalities, but few feature you want to show only in one of the app and hide those in the other one.</p><p><strong>Scenario 4:</strong> You want to white label your app.</p><blockquote>White labelling in Android simply means taking an existing app and rebranding it or customising it by changing the app’s icon, theme, styles, name, APIs, etc.</blockquote><p>If you are in these kind of situations, the quick thing that might come to your mind is to maintain a separate codebase for both variants of the app. But there can be some technical difficulties to maintaining different codebases. When there is a change in the code, we would need to do the same change in both the codebases, and this is a tedious process when the codebase is too large. So maintaining different codebases might not be a good approach in such a situation.</p><p>You can achieve these by using product flavours or flavour dimensions feature in android.</p><h3>Basics</h3><p>Android by default having two types of build types, debug and release. You are able to find these in build variants option, which you will be able to achieve in the bottom left corner of the android studio. Or simply you can press shift button twice and search for build variants, the section will automatically opens for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*cDidkJUgnEadzjdoWsJ_TA.png" /></figure><p>Addition of new build type can be done in the module level gradle file.</p><pre>buildTypes {<br>    debug {<br>        minifyEnabled false<br>        debuggable true<br>    }<br>    qa {<br>        minifyEnabled true<br>        debuggable false<br>    }<br>    release {<br>        minifyEnabled true<br>        debuggable false<br>        proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;<br>    }<br>}</pre><p>We have added 3 build types here : debug, qa and release. Now you can see these three build types in the build variants section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*mR0SyGu-fCt3Vz9RBZNfag.png" /></figure><p>You can select which build variant you want and can directly install the app from studio clicking on the ‘Run’ button.</p><p>Now when we run the app it will looks like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*1i1KfV5Hvdz7EaF3nY65Xg.png" /></figure><h3><strong>What is Product Flavours?</strong></h3><p>In simple words — <em>Consider preparing pizzas. You use same core ingredients to make the base but will use different toppings for each one to have a different taste. Similarly, android apps can have the same base functionalities and only some of the features like styles, logo etc can be changed with product flavours.</em></p><p>Product flavours let you create multiple variants of an app while using its existing codebase.</p><p>To create product flavours you need to define rules in the <strong>build.gradle </strong>which you will learn later in this blog.</p><h3>Steps to create product flavours</h3><p>Now consider you need to have the same app in two different colours say red and green. Let’s see how we can proceed by creating product flavours and here are the steps.</p><p><strong>Step 1 : Add product flavours in the build.gradle file</strong></p><p>Customize app level build.gradle by adding product flavours for red and green colours in the <strong>productFlavors</strong> section</p><pre>flavorDimensions &#39;default&#39;<br>productFlavors <strong>{<br>    </strong>redFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>    <strong>}<br>    </strong>greenFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>    <strong>}<br>}</strong></pre><p>Here, redFlavor is for the app variant with red color and greenFlavor is for app with green color.</p><p><strong>Navigate to build variants -&gt; </strong>Now when you navigate to build variants section, you should be able to see build variants for both of these flavours as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*iXwkcJRYQ0PFCx2YySD52w.png" /></figure><p><strong>Install App -&gt;</strong> If you select any of the variant in this and install app, you will be still able to see the app with the default colour as shown above.</p><p>So, the next thing is to see how to change the colour in different variants of app. To do that, follow the next step.</p><p><strong>Step 2 : Create resource folder for the flavours created</strong></p><p>Separate resource folder should be created for each of the variants where the colour should be specified. Create a res folder navigating to <strong>app -&gt;New -&gt; Folder -&gt; Res Folder</strong></p><p>You should be able to select the build variant for which you want to create the resource folder. Select the flavour and click finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*n3R5L_-mfdxLqTV1FIq7Lg.png" /></figure><p>Now a resource folder named <strong>res</strong> will be created inside <strong>src</strong> folder for the greenFlavor, since the greenFlavor is selected.</p><p><strong>Step 3 : Create colors.xml for the variant</strong></p><p>Now you can create colors.xml in the newly created folder under the location <strong>app -&gt; src -&gt; greenFlavor -&gt; res -&gt; values</strong></p><p><strong>Step 4 :</strong> <strong>Change colors, styles, logos etc.</strong></p><p>Now you need to add green colour in the res folder for the green flavor. For that, change primary and secondary colors in the new colors.xml file.</p><p><strong>Select the greenFlavor build variant and install the application -&gt;</strong></p><p>You should be able to see the colour of the toolbar changed to green.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*VT82Rgk8lLcu_5K5GqHZNg.png" /></figure><p>This way you should be able to customize the resources for each build flavour including styles, colors, themes, logos and even more.</p><h3>Project config properties</h3><p>There are various project config properties which can be maintained for the product flavours. Some of them are minSdkVersion, targetSdkVersion, versionName, versionCode and many more.</p><p>In the example below, you can see the minimum and maximum sdk versions are configured. You can also customise the values for the variants using buildConfigField and one such use case is to customise the host url for the application for each variants. The specified values can be accessed by <strong>BuildConfig.HOST_URL </strong>in this example.</p><pre>flavorDimensions &#39;default&#39;<br>productFlavors <strong>{<br>    </strong>redFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>        applicationId &quot;com.sample.productFlavors&quot;<br>        minSdkVersion 15<br>        targetSdkVersion 28<br>        buildConfigField &quot;String&quot;, &quot;HOST_URL&quot;, &quot;\&quot;host url 1\&quot;&quot;<br>    <strong>}<br>    </strong>greenFlavor <strong>{<br>        </strong>dimension &#39;default&#39;<br>        applicationId &quot;com.sample.productFlavors&quot;<br>        minSdkVersion 18<br>        targetSdkVersion 28<br>        buildConfigField &quot;String&quot;, &quot;HOST_URL&quot;, &quot;\&quot;host url 2\&quot;&quot;<br>    <strong>}<br>}</strong></pre><p>Now this is time to explore more…</p><p><strong>Happy learning &amp; Happy coding :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=426529d78cce" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>