<?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 Breera Hanif on Medium]]></title>
        <description><![CDATA[Stories by Breera Hanif on Medium]]></description>
        <link>https://medium.com/@breerahanif62?source=rss-144ff0fc991c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*AyDoEEgI3VNDcnXp</url>
            <title>Stories by Breera Hanif on Medium</title>
            <link>https://medium.com/@breerahanif62?source=rss-144ff0fc991c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 00:22:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@breerahanif62/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[Coroutine Cancellation]]></title>
            <link>https://medium.com/@breerahanif62/coroutine-cancellation-a194402b9a0a?source=rss-144ff0fc991c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a194402b9a0a</guid>
            <category><![CDATA[coroutines-in-kotlin]]></category>
            <category><![CDATA[synchronous-programming]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[coroutine]]></category>
            <dc:creator><![CDATA[Breera Hanif]]></dc:creator>
            <pubDate>Wed, 25 Jun 2025 12:56:15 GMT</pubDate>
            <atom:updated>2025-06-25T12:56:15.270Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3cXTy6SuiwwEV0LaesP94Q.png" /><figcaption>Image create by claude.ai</figcaption></figure><p>We all have seen and used coroutines in our daily development routine, and we’re all aware of their usage and advantages. This article is not about the main concepts and usage of coroutines, but rather focuses on their cancellation mechanisms and best practices.</p><p><strong>Why it is important to understand ?</strong></p><p>Understanding coroutine cancellation handling is crucial for building robust and responsive applications. Without proper handling, you may encounter:</p><ul><li><strong>Unexpected crashes</strong> that degrade user experience</li><li><strong>Resource leaks</strong> that impact app performance</li><li><strong>Unresponsive UI</strong> due to blocking operations</li><li><strong>Battery drain</strong> from unnecessary background work</li></ul><p>Proper cancellation ensures efficient resource management, while structured exception handling prevents silent failures. Mastering these concepts leads to smoother UI interactions, better stability, and more responsive applications.</p><p><strong>Cancellation in Coroutines</strong></p><p>Sometimes we need to cancel ongoing work (may be due to some reason like if user no more want to download a video etc.). The first thing that comes in mind is “just cancel the coroutine”. Hmm like <strong>job.canel()</strong> in coroutines.</p><h4>Does job.cancel() Really Work?</h4><p>You might be surprised to learn that simply calling job.cancel() doesn&#39;t immediately stop a coroutine. I was also surprised the first time I encountered this! 😁</p><p>Let’s explore this with a code example. I suggest opening Android Studio and trying each example yourself:</p><pre>fun testCoroutineCancel() {<br>    runBlocking {<br>        val job = launch(Dispatchers.Default) {<br>            var i = 0<br>            while (i &lt; 100) {<br>                println(&quot;I am running $i time&quot;)<br>                i++<br>            }<br>        }<br>        delay(5)<br>        job.cancel()<br>        println(&quot;Cancel called&quot;)<br>    }<br>}</pre><p>You might expect this coroutine to stop after job.cancel() is called, but it actually keeps printing and completes all iterations.</p><blockquote>The reason is that cancellation should be cooperative.</blockquote><h3>Making Coroutines Cooperative</h3><p>To make your coroutines properly respond to cancellation, you need to check if the coroutine has been cancelled. Here are the main approaches:</p><p><strong>1- </strong>Using<strong> <em>isActive (isActive </em></strong>is deprecated<strong><em>)</em></strong></p><p><strong><em>coroutineContext.isActive r</em></strong>eturns true when the current Job is still active (has not completed and was not cancelled yet). Try below code snippet, you will see the logs have been stopped printing once the job.cancel is called.</p><pre>runBlocking {<br>        val job = launch(Dispatchers.Default) {<br>            var i = 0<br>            while (i &lt; 100) {<br>                if (isActive) {<br>                    println(&quot;i am running $i time&quot;)<br>                    i++<br>                } else {<br>                    // clean up resources<br>                }<br>            }<br>        }<br>        delay(15)<br>        job.cancel()<br>        println(&quot;i am running cancel&quot;)<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AdrqkR8hxuripKVyZ3fjbw.png" /></figure><p><strong>When to use:</strong> When you need custom cleanup logic, logging, or graceful degradation.</p><p><strong>2- use <em>ensureActive: </em></strong>Use<strong><em> ensureActive </em></strong>at start of code block. It is extension of job and return cancellation exception if job is no active. Check official documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u80WlNANY5hjz-9Y3OQJXw.png" /></figure><p>It reduces the boilerplate code as you no more need to add if statement but see now you are not able to do something in else like logging etc. Try below code snippet, you will see coroutine has been cancelled and the logs have been stopped printing once the job.cancel is called.</p><pre>runBlocking {<br>            val job = launch(Dispatchers.Default) {<br>                var i = 0<br>                while (i &lt; 100) {<br>                    ensureActive()<br>                    delay(5)<br>                    println(&quot;i am running $i time&quot;)<br>                    i++<br>                }<br>            }<br>            delay(15)<br>            job.cancel()<br>            println(&quot;i am running cancel&quot;)<br>        }</pre><p><strong>Limitation:</strong> You cannot perform custom cleanup logic since it immediately throws an exception.</p><p><strong>When to use:</strong> For simple fail-fast cancellation without custom cleanup needs.</p><p><strong>3- yield():</strong> Yield can also be used as cancellation check point additionally it voluntarily gives up the current coroutine’s execution to allow other coroutines to run.If you want to cancel but want to ensure that other coroutines on the same dispatcher get a chance to run then use this. It serves as both a cancellation checkpoint and a cooperative scheduling mechanism.</p><pre> fun withYield() = runBlocking {<br>        val job = viewModelScope.launch(Dispatchers.IO) {<br>            repeat(5) {<br>                println(&quot;Coroutine A - $it&quot;)<br>            }<br><br>            repeat(5) {<br>                println(&quot;Coroutine B - $it&quot;)<br>            }<br>        }<br>    }</pre><p>The following code prints all Coroutine A first then prints All B. Now add <strong><em>yield() </em></strong>in above to understand the difference.</p><pre>fun withYield() = runBlocking {<br>        val job = viewModelScope.launch(Dispatchers.IO) {<br>            repeat(5) {<br>                println(&quot;Coroutine A - $it&quot;)<br>                yield()<br>            }<br><br>            repeat(5) {<br>                println(&quot;Coroutine B - $it&quot;)<br>                yield()<br>            }<br>        }<br>    }</pre><p>This interleaves the output, printing “Coroutine A — 0”, then potentially allowing other coroutines to run before continuing .<em>This</em><strong><em> </em></strong>is the additional benefit that you will get while using <strong><em>yield().</em></strong></p><p>Now Try the code snippet of <strong><em>ensureactive()</em></strong> but with <strong><em>yeild()</em></strong> and observe the result.</p><p><strong>4- Suspending function:</strong> Any suspending function (like delay()) makes the coroutine cooperative and responsive to cancellation:</p><p>Lets do comparison of all.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fdatawrapper.dwcdn.net%2FQU1jq%2F1%2F&amp;display_name=Datawrapper&amp;url=https%3A%2F%2Fdatawrapper.dwcdn.net%2FQU1jq%2F1%2F&amp;image=https%3A%2F%2Fdatawrapper.dwcdn.net%2FQU1jq%2Fplain-s.png%3Fv%3D1&amp;type=text%2Fhtml&amp;schema=dwcdn" width="600" height="775" frameborder="0" scrolling="no"><a href="https://medium.com/media/e635bbeaffc52a1f4e1c53ab38de30f6/href">https://medium.com/media/e635bbeaffc52a1f4e1c53ab38de30f6/href</a></iframe><h3>Exception Handling with Cancellation</h3><p>When working with cancellation, remember that CancellationException is special:</p><pre>try {<br>    // Some coroutine work<br>    ensureActive()<br>    // More work<br>} catch (e: CancellationException) {<br>    // Don&#39;t suppress cancellation exceptions<br>    // Perform cleanup if needed, then re-throw<br>    cleanup()<br>    throw e<br>} catch (e: Exception) {<br>    // Handle other exceptions<br>    handleError(e)<br>}</pre><h3>Conclusion</h3><p>Proper coroutine cancellation is essential for building responsive and efficient Android applications. By understanding when and how to use isActive, ensureActive(), yield(), and suspending functions, you can ensure your coroutines are well-behaved and responsive to cancellation requests.</p><p>Remember: <strong>cancellation must be cooperative</strong>. Choose the right cancellation strategy based on your specific needs — whether you need custom cleanup logic, simple fail-fast behavior, or cooperative multitasking.</p><p>In next section , we will look at different edge cases of coroutine exception and its handling.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a194402b9a0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Enums vs. Sealed Classes: Understanding the Differences]]></title>
            <link>https://medium.com/@breerahanif62/kotlin-enums-vs-sealed-classes-understanding-the-differences-f78075aeae1a?source=rss-144ff0fc991c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f78075aeae1a</guid>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[sealed-classes-in-kotlin]]></category>
            <category><![CDATA[sealed-classes]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[sealed-interface]]></category>
            <dc:creator><![CDATA[Breera Hanif]]></dc:creator>
            <pubDate>Sat, 22 Feb 2025 19:13:16 GMT</pubDate>
            <atom:updated>2025-02-22T19:26:26.626Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NndIciEoZ0V9vhnWzkYpkw.png" /><figcaption>AI Generated Image with prompt “Create a thumbnail for medium story with title ‘Kotlin Enums vs. Sealed Classes: Understanding the Differences’ .”</figcaption></figure><p>Being an engineer, we always in need of restricted set of values. Luckily as Kotlin developer, we have two powerful ways to handle restricted sets of values: enum and sealed classes. Both serve distinct purposes and have unique use cases. TBH i always found them similar thing (may be you also), but there is difference in them based on the use case . Let’s dive deep into them.</p><p>Firstly we will see them separately then we will go with difference.</p><h3>What is an Enum in Kotlin?</h3><p>An enum (short for enumeration) is a special class in Kotlin that represents a fixed set of constants (set of named constants). It is useful when you need to define a predefined set of values that should remain constant throughout the application.</p><pre>enum class PaymentStatus {<br>    PENDING,<br>    COMPLETED,<br>    FAILED<br>}</pre><h4>Key Features:</h4><ul><li>Each enum constant is an object (e.g. in above example Each value inside the enum class is an instance of the PaymentStatus type).</li><li>Enum may have properties and methods.</li></ul><pre>enum class PaymentStatus(private val description: String, private val guideline: String) {<br>    PENDING(&quot;Payment is pending&quot;,&quot;Process with payment to continue&quot;),<br>    COMPLETED(&quot;Payment is completed&quot;,&quot;You can Proceed with Premium features&quot;),<br>    FAILED(&quot;Payment failed&quot;,&quot;Ah! Try Again&quot;);<br><br>    fun userStatus() :String {<br>        return &quot;$description , $guideline&quot;<br>    }<br>}<br><br>// use it like this <br>println(PaymentStatus.FAILED.userStatus())<br><br>// it will print <br>// Payment failed , Ah! Try Again</pre><p>You can get advantages of methods in enums in a way that you can associate behavior with each constant. For example, in a logging system, you can define different log levels with corresponding actions:</p><pre>enum class LogLevel(val level: Int) {<br>    INFO(1) {<br>        override fun logMessage(message: String) = println(&quot;INFO: $message&quot;)<br>    },<br>    WARN(2) {<br>        override fun logMessage(message: String) = println(&quot;WARNING: $message&quot;)<br>    },<br>    ERROR(3) {<br>        override fun logMessage(message: String) = println(&quot;ERROR: $message&quot;)<br>    };<br>    <br>    abstract fun logMessage(message: String)<br>}</pre><p>Note that before adding method after last constant , we are adding semi colon(;) instead of comma(,).</p><h4>When to Use Enums:</h4><ul><li>When you have a fixed set of related constants.</li><li>When values should remain constant and not change dynamically.</li><li>When each enum constant may have associated properties or behaviors.</li><li>When you need Type-safe alternatives to constants.</li><li>When you need to show constant data like in a drop down.</li></ul><h4>Limitations:</h4><ul><li>Enums are rigid and cannot be extended at runtime.</li></ul><h3>What is Sealed Class in Kotlin?</h3><p>A sealed class is a type of class that restricts its subclasses to a defined set within the same file.</p><pre>sealed class ApiResponse {<br>    data class Success(val data: String) : ApiResponse()<br>    data class Error(val message: String) : ApiResponse()<br>    data object Loading : ApiResponse()<br>}</pre><h4>Key Features:</h4><ul><li>Unlike enum, sealed classes can hold different types of data and state and they have multiple instances.</li><li>Like enum, Sealed classes may have properties.</li><li>Sealed classes are abstract by default.</li><li>All subclasses must be declared in the same file.</li></ul><pre>sealed class ApiResponse(val status: String) {<br>    data class Success(val data: String) : ApiResponse(&quot;Success&quot;)<br>    data class Error(val message: String) : ApiResponse(&quot;Error&quot;)<br>    object Loading : ApiResponse(&quot;Loading&quot;)<br>}</pre><h4>When to Sealed Class :</h4><ul><li>When you need a limited set of subclasses with different properties.</li><li>When different states in a state machine need to be represented.</li><li>When used with when expressions to ensure all cases are handled. The when expression, used with a sealed class, allows the Kotlin compiler to check exhaustively that all possible cases are covered. In such cases, you don&#39;t need to add an else clause.</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fdatawrapper.dwcdn.net%2FlURwB%2F1%2F&amp;display_name=Datawrapper&amp;url=https%3A%2F%2Fdatawrapper.dwcdn.net%2FlURwB%2F1%2F&amp;image=https%3A%2F%2Fdatawrapper.dwcdn.net%2FlURwB%2Fplain-s.png%3Fv%3D1&amp;type=text%2Fhtml&amp;schema=dwcdn" width="600" height="468" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a93358167252675673d4cacbd7da2b0/href">https://medium.com/media/9a93358167252675673d4cacbd7da2b0/href</a></iframe><h3>Conclusion</h3><p>Both enum and sealed classes are useful in Kotlin for handling restricted sets of values but serve different purposes. Enums are best when working with predefined constants, while sealed classes are ideal when dealing with different states with various data types. Choosing the right one depends on your use case!</p><p><strong>Bonus point:</strong> If you don’t need constructor in sealed class then you can make it sealed interface as sealed interface has no any constructor.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f78075aeae1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migration from BuildSrc to Composite Build System]]></title>
            <link>https://medium.com/@breerahanif62/migration-from-buildsrc-to-composite-build-system-494da5667a95?source=rss-144ff0fc991c------2</link>
            <guid isPermaLink="false">https://medium.com/p/494da5667a95</guid>
            <category><![CDATA[buildsrc]]></category>
            <category><![CDATA[migration-of-builssrc]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[composite-build]]></category>
            <dc:creator><![CDATA[Breera Hanif]]></dc:creator>
            <pubDate>Sun, 22 Dec 2024 18:55:46 GMT</pubDate>
            <atom:updated>2024-12-23T05:13:07.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ch-bTBVEL07Wl6w-00cuLw.png" /><figcaption>AI-generated Image</figcaption></figure><p>Today, I was assigned to move our YAP-PK project from buildSrc to a composite build. This task raised one question in my mind</p><p>Why make this change if everything is already working fine? 🤔🤔🤔🤔</p><p>Based on my research and findings, I want to share the story behind this migration and outline all the steps I followed to complete it.</p><p>Currently, we are using BuildSrc in our YAP-PK project. This approach was although great blessing at the time of creation. However, time added many new concerns to it as soon as developers started making it a practice. Some of them are listed below:</p><h3>Drawbacks of Using BuildSrc</h3><p>BuildSrc is a special convention-based directory in Gradle projects for managing custom build logic and plugins. There are many great articles on BuildSrc’s benefits and implementation. While convenient, it has several limitations:</p><ol><li><strong>Global Scope</strong>: BuildSrc is automatically included in every module of the project, even if only some modules require its functionality. This increases build complexity and can lead to unintentional coupling.</li><li><strong>Build Performance</strong>: Changes to buildSrc trigger a full project rebuild because Gradle treats it as part of the build script. This can lead to slower build times for large projects.</li><li><strong>Limited Reusability</strong>: BuildSrc cannot easily be reused across multiple projects or shared between teams unless copied manually, which is error-prone and redundant.</li><li><strong>Versioning Constraints</strong>: Since BuildSrc is tightly coupled to the project, managing versions for different use cases (e.g., different versions of a plugin for different modules) becomes cumbersome.</li><li><strong>Inflexibility for Scaling</strong>: As projects grow, the centralised nature of BuildSrc can become a bottleneck, making it difficult to modularize and maintain build logic independently.</li></ol><h3>Why Move to Composite Builds?</h3><p>Composite builds offer several advantages over BuildSrc:</p><ol><li><strong>Better Modularity</strong>: By separating build logic into independent composite modules, you can organize and manage it more effectively, making it easier to maintain and scale.</li><li><strong>Improved Build Performance</strong>: Changes to composite build projects do not trigger full project rebuilds, leading to faster incremental builds.</li><li><strong>Enhanced Reusability</strong>: Composite builds can be reused across different projects by including them as dependencies, avoiding duplication and improving maintainability.</li><li><strong>Versioning Flexibility</strong>: Composite builds can manage their versions independently, allowing for multiple versions of build logic to coexist.</li><li><strong>Easier Collaboration</strong>: Teams can work on separate composite build projects in isolation, reducing the risk of conflicts in a shared BuildSrc directory.</li></ol><h3>“A composite build is simply a build that includes other builds. In many ways, a composite build is similar to a Gradle multi-project build, except that instead of including single projects, complete builds are included.”</h3><p><strong>Migration Steps: </strong>The following are the steps to move YAP-PK to composite build. Let’s start with me, You can follow the same approach for other projects as well. There may be some changes for some projects but the main idea will be the same.</p><blockquote><strong><em>Don’t delete buildSrc at the start, it will stop your project to build. We will remove classes safely one by one</em></strong></blockquote><p><strong>Step 1: </strong>Firstly, I created a TOML file and added whole app versions and dependencies from BuildSrc folders to the TOML file. Make sure you don’t skip any dependency and plugins.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1afjg4ZMY4cFaynW7Uxf7Q.png" /><figcaption>App module <strong>build. gradle.kts</strong>: Plugins refer to constant of an object class BuildPluginsConfig from BuildSrc</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ycCV8gKJBns2N4lNDbCMuw.png" /><figcaption>App module <strong>build.gradle.kts: </strong>After referring to versions from TOML</figcaption></figure><p>Once you update all plugins and dependencies, rebuild your project. Once the project rebuilds successfully, remove the classes from buildSrc that contain these dependencies.</p><p><strong>Step 2: </strong>I created a module (android library) as: name = <strong>:build-system:build-logic</strong> and package <strong>com.yourpackage.build.logic</strong>. Here build-system is like a new project and the build-logic is a module inside. Enter : build-system:build-logic in the module name field. This configuration will establish a build-system folder and a module called build-logic within this. Here, we’ll house all our plugins and any module-specific build scripts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fnbyakVPpleVqaZ5CW2WNQ.png" /></figure><p><strong>Step 3:</strong> After that set up, i added <strong>.gitignore</strong>, <strong>gradle.properties</strong>, and <strong>settings.gradle.kts</strong> in build-system folder to make it behave like a project and add the following in <strong>settings.gradle.kts.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FtUgFI01euXzyDRF_mQIww.png" /><figcaption>build-logic : Settings.gradle.kts</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4d7e4cbd0a5e497e31c3dd3772c2ba7/href">https://medium.com/media/f4d7e4cbd0a5e497e31c3dd3772c2ba7/href</a></iframe><p>The code is self-explanatory. We registered our version catalog and included the build-logic module.</p><p><strong>Step 4:</strong> I Updated the project level <strong>settings. gradle.kts</strong> file. Doing so makes the build module visible to Gradle during the build process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fjGq5DEmpVId7BbA5YhTA.png" /><figcaption>project level: settings.gradle.kts</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dee4e47f4b49c044eaa6bf30e5b0b86/href">https://medium.com/media/2dee4e47f4b49c044eaa6bf30e5b0b86/href</a></iframe><p>In the pluginManagement, we added our build system.</p><pre>includeBuild(&quot;build-system&quot;)</pre><p>We eliminated the redundant convention module definition at the bottom, Additionally, we’ve activated type-safe project accessors.</p><p><strong>Step 5:</strong> Next in build_system:build_logic’s build.gradle, I added following. This Gradle script sets up the project for build-logic. It enforces strict validation for plugins to ensure high code quality, with a validation task that fails on warnings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dgeVLC4q7Ccz8rgiqPpqVg.png" /><figcaption>build-logic: build.gradle.kts</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ec925c8c3af9fdb3dc0512111b20838/href">https://medium.com/media/8ec925c8c3af9fdb3dc0512111b20838/href</a></iframe><p><strong>Step 6:</strong> I synced the project at that point, and everything was working fine. Click at Gradle and It should look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*c2g97EW8FaQ2M-qlU29HTQ.png" /><figcaption>Project structure</figcaption></figure><p>At this point again make sure there should be no dependency or version variable defined in your BuildSrc folder. Everything should only point to TOML (Now our single source of truth). I safely deleted all files pointing versions and dependencies in buildSrc at that point to make things clearer. Let’s move to plugin section.</p><p><strong>Step 7:</strong> If you don’t have a plugin then create it to take advantage of composite build system, I had already scripts at that time in PK project. There were two scripts for app module, One was for signing config and one was for Android application-specific settings, such as compile and target SDK versions, packaging options, and build features like View Binding and Data Binding, to standardize the project’s build process. I created a new plugin <strong>AndroidAppModulePlugin</strong> in a new package plugin and combined both in a single plugin. Make sure to use the same variable, keystore-setting etc. in the new plugin.</p><p>(Not describing how plugin was created, for this we may meet in some other discussion)</p><p>The package hierarchy was as follows , extension package has some utilities functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yMnklQSGGVfjz-BUQUpXuQ.png" /></figure><p>Now register the plugin in <strong>build.gradle.kts</strong> of build-logic</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CaXF6sSA0c2WmSjTIhVF9Q.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0a7ce6bc642d31725b7de96f725c3ce/href">https://medium.com/media/c0a7ce6bc642d31725b7de96f725c3ce/href</a></iframe><p>Add the plugin in plugin section of TOML</p><pre>app-plugin = { id = &quot;com.yourpackage.app.plugin&quot; }</pre><p>Apply the plugin to app module and removed other plugins</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SWG7uv9SAq6gKw8wjDaXiQ.png" /></figure><p>Pretty Clean. You can scroll and check above the previous bunch of plugins. Actually most configurations require for app module are now part of app plugin already.</p><p>Sync and run. Also create an APK/bundle to check your signing configuration at this time. After a successful run, delete the scripts from BuildSrc used for app configuration.</p><p><strong>Step 8:</strong> Did the same for the library script.</p><ul><li>Create a plugin for the library</li><li>Register the plugin</li><li>Add it in TOML</li><li>Apply to all library module</li><li>Sync , rebuild and generate APK/bundle</li><li>Safely delete library script from BuildSrc.</li></ul><p><strong>Step 9:</strong> Now I had only some quality regarding scripts in buildSrc , for now I just created script folder and move them in build-logic and apply them like above. The final hierarchy was as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*4DyBxgoyv36tw6MnajI5CQ.png" /></figure><p>Sync run and delete quality scripts. The final app is now as follow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bBBo4wYQpg2uLY4ft2IVbg.png" /><figcaption>Blue print of composite build system of app</figcaption></figure><p>Note: Base Plugin has the maximum common functionality of all plugins. Extension module has some utilities for creating plugins.</p><p>Congratulations🎉 our BuildSrc is now an empty folder. Safely delete it. We have done our migration. We are in composite-build system now.</p><p>What will come next</p><ul><li>How to create and proper formate a TOML file using some plugins and make user restrict on it.</li><li>How plugins are created. Sample app and library plugins</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=494da5667a95" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>