<?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 Jakub Komorowski on Medium]]></title>
        <description><![CDATA[Stories by Jakub Komorowski on Medium]]></description>
        <link>https://medium.com/@jakub.komorowski?source=rss-c596c07455da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*n0J7XH1NwxUQkjrbziU2jw.jpeg</url>
            <title>Stories by Jakub Komorowski on Medium</title>
            <link>https://medium.com/@jakub.komorowski?source=rss-c596c07455da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 09:27:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jakub.komorowski/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[Animating RecyclerView items]]></title>
            <link>https://blog.codequest.com/animating-recyclerview-items-8112ba164661?source=rss-c596c07455da------2</link>
            <guid isPermaLink="false">https://medium.com/p/8112ba164661</guid>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[application-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Jakub Komorowski]]></dc:creator>
            <pubDate>Fri, 07 Aug 2020 09:30:08 GMT</pubDate>
            <atom:updated>2025-02-28T13:11:25.913Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pY7ck0SSlTSwd9Kr-XXCqw.gif" /></figure><p>In the project I was recently working on I was asked to implement a list with item animations upon their entrance on and exit from screen. The animations would play when the item view entered or exited the zone in the top, or the bottom of the view. In this article I will outline how I implemented this effect and how you can also do this in your application using your code, or the simple library I wrote to achieve this effect.</p><h3>Basic implementation</h3><p>To accomplish our goal we would need to access RecyclerView’s children in its onScrolled method to start entrance or exit animation. For that we could create AnimatedRecyclerView class that extends RecyclerView. Then, in onScrolled we could check whether the views should be animated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af41fe082397ad465f9b51c5dd6fa81c/href">https://medium.com/media/af41fe082397ad465f9b51c5dd6fa81c/href</a></iframe><p>Now we need to implement methods that would check if the view did enter or exit the screen. To do that we need to check whether top or the bottom of the item view has crossed a border from the top of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*6_E9WkDG55Ujb2jYNtsJGg.png" /><figcaption>Items entering the screen from the top and exiting a screen to the bottom on scroll down</figcaption></figure><p>As you can see in the above picture we need to check whether bottom of the item view changed their y coordinate from lesser than the y position of the animation margin line to the one larger than that. That way we could figure out if the view has entered the screen from the top. We can express it in code as:</p><pre>bottom &gt;= topMarginY &amp;&amp; bottom + dy &lt; topMarginY</pre><p>Where bottom is y coordinate of the bottom of the item view, topMarginY is y coordinate of the top margin line and dy is amount scrolled.</p><p>The first part of the expression checks whether the bottom of the item view is below margin line after scroll, the second on — whether it was above before the scroll.</p><p>In a similar fashion we can check if the top of the view crossed the bottom margin line during a scroll:</p><pre>top &gt;= bottomMarginY &amp;&amp; top + dy &lt; bottomMarginY</pre><p>With those two expressions we can figure out if the view has entered or exited the ScrollView during scroll down. To complete the solution we now need to add checks for scrolling up. For exiting to the top of the screen we can use expression:</p><pre>bottom &lt;= topMarginY &amp;&amp; bottom + dy &gt; topMarginY</pre><p>and for entering from the bottom of the screen:</p><pre>top &lt;= bottomMarginY &amp;&amp; top + dy &gt; bottomMarginY</pre><p>We can now combine those expressions to implement the methods in our AnimatedRecyclerView class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04946c2e9cc237429be2f25a812f73f7/href">https://medium.com/media/04946c2e9cc237429be2f25a812f73f7/href</a></iframe><p>This basic implementation allows us to animate views that are scroll into the screen, and scroll out of it. The downside is the animations will apply to all of the views in the RecyclerView — we can’t really differentiate between them easily, and for each list with different animations we need different AnimatedRecyclerView implementation.</p><h3>Improvements</h3><p>To improve upon the basic solution we can move the animation to the ViewHolders used by the RecyclerView’s Adapter. To implement that, however, we need to gain access to the instances of view holders associated with the item views currently visible in the RecyclerView. The class itself does not provide a method to access those view holders, so some additional code is required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/725df30ad0955433f2c66e2020d0737b/href">https://medium.com/media/725df30ad0955433f2c66e2020d0737b/href</a></iframe><p>First we need to create an abstract implementation of ViewHolder with the callback methods needed to inform it of the events related to its view entering or exiting the screen. You might notice that separate callbacks for the top and bottom of the screen events were created, so different animations could be applied.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/289052934c3e1ff9c16e3078991afa9d/href">https://medium.com/media/289052934c3e1ff9c16e3078991afa9d/href</a></iframe><p>Next we need to add a list of view holders associated with item views currently added to the recycler view, and methods for adding and removing elements to that list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83b477e4da93313be5699c673846ebc4/href">https://medium.com/media/83b477e4da93313be5699c673846ebc4/href</a></iframe><p>The methods we added in AnimatedRecyclerView have to be called by our adapter implementation, as it has the callback methods for the view attached and detached events.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27754fe6b5ee066636b3f88a87eab302/href">https://medium.com/media/27754fe6b5ee066636b3f88a87eab302/href</a></iframe><p>Finally we can finish AnimatedRecyclerView implementation. The conditions for checking whether the views entered or exited top or the bottom of the screen can be split into different methods, and based on them we can run methods from AnimatedItemHolder class.</p><h3>Usage</h3><p>With those improvements we can easily reuse the code we wrote by using our AnimatedRecyclerView in our views, and extending AnimatedRecyclerAdapter and AnimatedItemHolder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63876ab1f7f9432a42d1d8ec1d080e86/href">https://medium.com/media/63876ab1f7f9432a42d1d8ec1d080e86/href</a></iframe><p>As you see this implementation has only one view holder and uses the same animation for items entering from and exiting to both top and bottom of the screen. However, nothing stops us from implementing few different view holders for different view types, and implementing different animations for top and bottom of the screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c5fe5b09dd7b2c8d406988938b4ec18/href">https://medium.com/media/5c5fe5b09dd7b2c8d406988938b4ec18/href</a></iframe><p>You can find complete implementation with example usage here: <a href="https://github.com/codequest-eu/AnimatedRecyclerView">https://github.com/codequest-eu/AnimatedRecyclerView</a> . If you have any ideas on how this code could be upgraded, let me know. Happy coding!</p><p>💌 <strong>You like stories like this? Don’t miss out — </strong><a href="https://medium.com/codequest/newsletters/codequest"><strong>join our newsletter!</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8112ba164661" width="1" height="1" alt=""><hr><p><a href="https://blog.codequest.com/animating-recyclerview-items-8112ba164661">Animating RecyclerView items</a> was originally published in <a href="https://blog.codequest.com/">codequest</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File Group Templates in Android Studio — Unofficial Guide]]></title>
            <link>https://blog.codequest.com/file-group-templates-in-android-studio-unofficial-guide-85dfa0a0c1ec?source=rss-c596c07455da------2</link>
            <guid isPermaLink="false">https://medium.com/p/85dfa0a0c1ec</guid>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[ide]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[file-templates]]></category>
            <dc:creator><![CDATA[Jakub Komorowski]]></dc:creator>
            <pubDate>Tue, 13 Aug 2019 12:54:11 GMT</pubDate>
            <atom:updated>2025-02-28T12:55:40.906Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fHFwYMEa9xWpdZjqjLUVUQ.jpeg" /><figcaption>by <a href="https://medium.com/u/bf09fb8eff2a">Wero Lasota</a></figcaption></figure><h3>File Group Templates in Android Studio — Unofficial Guide</h3><p>Android Studio (and other JetBrains IDEs) offer two easily accessible options for creating code snippets and whole files from templates — live templates and file templates. You can add, delete, and edit them in IDE preferences. But what if you want to create multiple files at once? That’s where group templates come in. Android Studio comes with bundled file group templates — you have probably already used them when creating ActivitiesY’all or Fragments. You cannot modify those templates from the IDE itself, but they can be found in the Android Studio directory. You can add your own templates there, or edit the existing ones.</p><h3>Group File Templates Location</h3><p>Group file templates can be found in the following locations:</p><ul><li>on MacOS</li></ul><pre><em>/Applications/Android Studio.app/Contents/plugins/android/lib/templates</em></pre><ul><li>on other OSes:</li></ul><pre><em>{ANDROID_STUDIO_LOCATION}/plugins/android/lib/templates/other/</em></pre><p>Bundled file templates are grouped in the following folders in the aforementioned directory — activities, gradle, gradle-projects, other. You can add new templates into those folders, or create separate folders for your templates.</p><p>Every new group file template must be contained in its own folder, and this folder has to be placed in one of the group folders. New templates have to be placed in the following directory:</p><pre>…/templates/{<strong>GROUP_FOLDER_NAME</strong>}/{<strong>TEMPLATE_NAME</strong>}/</pre><p><strong>GROUP_FOLDER_NAME</strong> — can be an existing folder’s name (such as <em>activities</em>), or a new folder — for example <em>my_activities</em>.</p><h3>File Group Template Structure</h3><p>Group template typically contains the following files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*hIFepHtBxGKkQ8LfWKr9Fw.png" /><figcaption>Typical structure of the group template files</figcaption></figure><p>There are two type of files used for creating file group templates — XML, and <a href="https://freemarker.apache.org/">Freemarker</a> (with .ftl extension). According to the project’s website:</p><blockquote>Freemarker is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data.</blockquote><p>Full documentation of Freemarker can be found <a href="https://freemarker.apache.org/docs/">here</a>.</p><h3><strong>Template file</strong></h3><p>The name of this file has to be <strong>template.xml</strong>. Otherwise IDE won’t recognize it as such, and the file template defined in this file won’t show up in new files picker. It is technically the only file needed for the template to appear in Android Studio. It defines the template’s name, description, and parameters that can be inputted by the user. It has the following structure:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3838c1ca025c88cf880dc5fa2e389f8e/href">https://medium.com/media/3838c1ca025c88cf880dc5fa2e389f8e/href</a></iframe><h4><strong>template</strong></h4><p>Element defining the file group template.</p><ul><li><strong>name </strong>— name of the template, visible to the user in the new file list;</li><li><strong>description </strong>— template description, visible at the top of the new file group dialog;</li></ul><h4><strong>category</strong></h4><ul><li><strong>value</strong> — category in which the template would show in, it creates a new category in the file picker if there was no such category;</li></ul><h4><strong>parameter</strong></h4><ul><li><strong>id</strong> — parameter name that can be used to reference parameter’s value in template files;</li><li><strong>name</strong> — parameter name visible to the user;</li><li><strong>type</strong> — typ of the parameter, e.g. ‘string’;</li><li><strong>constraints</strong> — constraints of the input, can take following values: <em>layout</em>, <em>unique</em>, <em>nonempty,</em> <em>package</em>;</li><li><strong>default</strong> — default value of the parameter, can reference other parameters, e.g. we could use this feature to generate an activity’s layout name based on a feature name :</li></ul><pre>“activity_${featureName}”</pre><ul><li><strong>help</strong> — optional parameter that defines a hint that appears at the bottom of the new component dialog when the user is editing a particular parameter’s value.</li></ul><h4><strong>globals</strong></h4><ul><li><strong>file</strong> — relative path to <strong>globals.xml.ftl</strong> file;</li></ul><h4><strong>execute</strong></h4><ul><li><strong>file</strong> — relative path to <strong>recipe.xml.ftl</strong> file;</li><li><strong>thumbs</strong> — optional element containing image file paths to the preview picture visible in new the file group dialog.</li></ul><h3><strong>Globals file</strong></h3><p>This file defines the variables accessible in all of the template files. It is commonly is named <strong>globals.xml.ftl</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a6fc89ef045c3b54ade22c7138d0728/href">https://medium.com/media/5a6fc89ef045c3b54ade22c7138d0728/href</a></iframe><h4><strong>#assign</strong></h4><p>With this directive you can create new variable, or replace an existing variable. Variables in this element would be visible only within this element. Full documentation for this directive can be found <a href="https://freemarker.apache.org/docs/ref_directive_assign.html">here</a>.</p><h4><strong>global</strong></h4><p>Element defining globally visible variable</p><ul><li><strong>id</strong> — name of the variable that can be referenced in template files;</li><li><strong>value</strong> — value of the variable. Can be either string literal, or a method call.</li></ul><h4>#include</h4><p>Directive for including external files containing global variables definition. Useful when we want to re-use the same variables for multiple templates. The included file has the same structure as the main globals file.</p><h3>Recipe file</h3><p>Recipe files contain instructions for the processor pertaining to file creation and modification. In existing templates it is called <strong>recipe.xml.ftl</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0da8e18923cb88de396973f217ad0c0/href">https://medium.com/media/f0da8e18923cb88de396973f217ad0c0/href</a></iframe><h4>include</h4><p>Directive for including external recipes, useful when we want to re-use the same recipe in multiple templates.</p><h4>merge</h4><p>This element is used to merge xml elements into existing xml files. It is most commonly used for merging <strong>activity</strong> elements into <strong>AndroidManifest.xml</strong>. It can’t be used with other file types, such as Kotlin or Java files.</p><h4><strong>instantiate</strong></h4><p>This element is used to create a new file based on the file template.</p><h4>open</h4><p>Using this element you can define which files will be opened after the template has been executed.</p><h3>Template files</h3><p>Those are the files which will serve as a base for files created during the template processing. They have <strong>.ftl</strong> extension, usually preceded by the result file extension, for example <strong>MyActivity.kt.ftl</strong> for Activity written in Kotlin. The template file can look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0523a9745b19791f3b7246de2dfe768e/href">https://medium.com/media/0523a9745b19791f3b7246de2dfe768e/href</a></iframe><p>You can reference variables defined in <strong>globals.xml.ftl</strong> file in your templates. You can also use methods here.</p><h3>Freemarker methods</h3><p>There are various built-in methods available in Freemarker that you can call on your defined variables. For example, if you defined a string variable named <strong>myVariable</strong>, you can call a method on it like so:</p><pre>myVariable?capitalize</pre><p>The full reference for built-ins can be found <a href="https://freemarker.apache.org/docs/ref_builtins.html">here</a>.</p><h3>Conversion methods</h3><p>Beside standard Freemarker built-in methods you can also use conversion methods added by JetBrains. There’s no official reference for those, but all of them can be seen in the source code of their <strong>FreemarkerUtil::createParameterMap </strong>method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a669ad37b9167848111cdfa21c3513e/href">https://medium.com/media/5a669ad37b9167848111cdfa21c3513e/href</a></iframe><p>Those methods can be called like Java methods, and take zero or more variables as an argument, for example:</p><pre>${activityToLayout(myVariable)}</pre><p>Those methods are not really documented anywhere, but if you want to figure out what exactly they do, you can check the tests for them, which can be found here:</p><p><a href="https://github.com/JetBrains/android/tree/master/android/testSrc/com/android/tools/idea/templates">JetBrains/android</a></p><p><strong>activityToLayout</strong> — takes one string argument, and returns a string with activity name converted to layout name, for example “FooActivity” would be converted to “activity_foo”;</p><p><strong>camelCaseToUnderscore</strong> — takes one string argument, as the name implies, converts camel case strings to underscored ones, e.g. “FooBar” would be converted to “foo_bar”;</p><p><strong>classToResource</strong> — takes one string argument, converts Android components names to resource names, e.g. calling this method for both “FooActivity”, or “FooFragment” would produce “foo”;</p><p><strong>compareVersions</strong> — two string arguments, both describing a Gradle version — usually three numbers separated by dots, with an optional suffix. For example “1.0.0”, “10.5.1”, or “2.2.0-dev”. Then it parses the arguments <a href="https://github.com/JetBrains/adt-tools-base/blob/master/sdk-common/src/main/java/com/android/ide/common/repository/GradleVersion.java"><em>GradleVersion</em></a> objects and compares them using <em>GradleVersion::compareTo</em> method. It can return three integer values — either 1 if the first argument is greater than the second, 0 if the arguments are identical, or -1 if the second argument is greater than the first.</p><p><strong>compareVersionsIgnoringQualifiers </strong>— the same as <strong>compareVersions</strong>, but uses <em>GradleVersion::compareIgnoringQualifiers</em> method for comparison.</p><p><strong>escapePropertyValue</strong> — takes one string argument, and returns a string with removed escaping backslashes — for example calling the method with “\\ foo “ argument will produce “ foo “.</p><p><strong>escapeXmlAttribute</strong> — takes one string argument and returns a string with escaped xml characters. E.g. for “&lt;\”’&gt;&amp;” the method will produce “&amp;lt;&amp;quot;&amp;apos;&gt;&amp;amp;”.</p><p><strong>escapeXmlString</strong> — takes one string argument and returns a string with xml characters escaped. E.g. calling this method with “Hello\nWorld” argument, would return “Hello\\nWorld”.</p><p><strong>escapeXmlText</strong> — takes one string argument and returns string converted to Xml-attribute-safe value. Seems to yield the same results as <strong>escapeXmlString</strong>, but uses different method for conversion internally.</p><p><strong>extractLetters</strong> — takes one string argument and returns string containing only letter characters from that string, e.g. calling the method with “&lt;\’&gt;&amp;foo “ argument would produce “foo”.</p><p><strong>getAppManifestDir</strong> — returns the path to the directory in which app manifest is stored, e.g. for MacOS that would be:</p><pre>/Users/{UserName}/{ProjectDirectory}/app/src/main</pre><p><strong>getApplicationTheme</strong> — returns map containing application theme name (e.g. “AppTheme”), boolean denoting whether application theme inherits from AppCompat theme, and whether the application has an application theme at all. You can access those arguments by calling “getApplicationTheme().name”, “getApplicationTheme().isAppCompat”, and “getApplicationTheme().exists”.</p><p><strong>isAndroidxEnabled</strong> — returns boolean if the project uses AndroidX libraries.</p><p><strong>getConfigurationName</strong> — returns currently used configuration name, such as “implementation”.</p><p><strong>getMaterialComponentName</strong> — takes two arguments, first of them being a name of an Android view class, and the second — a boolean denoting whether a new class name should be used. Calling this method with “android.support.design.widget.FloatingActionButton” and true arguments it returns “com.google.android.material.floatingactionbutton.FloatingActionButton” which is the name of the new FloatingActionButton class.</p><p><strong>hasDependency</strong> — takes two string arguments, first of them being a library name, and second — a configuration name, and returns a boolean denoting whether specified configuration depends on specified library.</p><p><strong>isGradleComponentPluginUsed</strong> — returns boolean denoting whether the Gradle component plugin (AKA experimental plugin) is used for a given module.</p><p><strong>layoutToActivity</strong> — takes one string argument and returns string with layout name converted to activity name, for e.g. for “activity_foo” this method will return “FooActivity”.</p><p><strong>slashedPackageName </strong>— takes one string argument in format of a Java package name and returns string containing relative path to this package. E.g. calling this method with “com.example.foo” argument will return “com/example/foo”.</p><p><strong>truncate</strong> — takes two arguments, a string and an int, and returns the argument string truncated to first n characters, where n is the second argument.</p><p><strong>underscoreToCamelCase</strong> — takes one string argument and returns argument string converted to camel case.</p><p><strong>escapeKotlinIdentifiers</strong> — takes one string argument and returns string with all of the Kotlin keywords escaped with `` characters. For example, for “foo.in.bar.is” the method will return “foo.`in`.bar.`is`”.</p><h3>Example of custom file group template</h3><p>To accelerate Android applications development here at Codequest we created file group templates for MVI Activities and Fragments that take care of creating all of the classes and files required by this architecture. It can be found here:</p><p><a href="https://github.com/kubak89/MVI-Android-Templates">kubak89/MVI-Android-Templates</a></p><p>If you have any further questions on the topic, or think I omitted some aspect of creating file group templates in Android Studio, please let me know! I would like to make this guide as comprehensive as possible, so I will try update it according to your comments.</p><p>Thank you for reading and happy coding!</p><p>💌 <strong>You like stories like this? Don’t miss out — </strong><a href="https://medium.com/codequest/newsletters/codequest"><strong>join our newsletter!</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85dfa0a0c1ec" width="1" height="1" alt=""><hr><p><a href="https://blog.codequest.com/file-group-templates-in-android-studio-unofficial-guide-85dfa0a0c1ec">File Group Templates in Android Studio — Unofficial Guide</a> was originally published in <a href="https://blog.codequest.com/">codequest</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gradle multi project build — substituting jar dependencies with local projects]]></title>
            <link>https://blog.codequest.com/gradle-multi-project-build-substituting-jar-dependencies-with-local-projects-4a5323f8680b?source=rss-c596c07455da------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a5323f8680b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[groovy]]></category>
            <dc:creator><![CDATA[Jakub Komorowski]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 09:12:07 GMT</pubDate>
            <atom:updated>2019-04-12T09:12:07.542Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62GJBXP7cikAdwCBiiI7ug.jpeg" /><figcaption>by <a href="https://medium.com/u/bf09fb8eff2a">Wero Lasota</a></figcaption></figure><h3>Gradle multi project build — substituting jar dependencies with local projects</h3><p>One of the projects we’re working on recently is using a multi-module architecture. Each feature module is kept in a separate Git repository, built into a jar, and uploaded to a remote repository. Those libraries are then added to the main application as Gradle dependencies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35461a002fbb6ef888c2c78eb4d3637b/href">https://medium.com/media/35461a002fbb6ef888c2c78eb4d3637b/href</a></iframe><p>We have come across several problems when working with such a setup. Code was hard to navigate, and simultaneous changes in multiple modules were hard to test. That’s when we came across Gradle multi-project builds and dependency substitution.</p><h3>Setting up a multi-project build with multiple repositories</h3><p>Gradle multi-project build is the feature used when building Android projects with multiple modules. In Gradle terminology, each Android module is Gradle project. If your Gradle projects are all in a root project directory you can include them by simply adding them in settings.gradle file in a root directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bed5e3a7215ce79d9356fe005d61052/href">https://medium.com/media/4bed5e3a7215ce79d9356fe005d61052/href</a></iframe><p>But what if each of my feature modules is in a separate git repository? One way to do that would be to use git submodules, but I was advised against it. The solution was to clone module repos into separate directories and specify their paths in setting.gradle file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a570bef4d8835b4875656f2cd25a5fbd/href">https://medium.com/media/a570bef4d8835b4875656f2cd25a5fbd/href</a></iframe><h3>Dependency substitution</h3><p>Setting up a gradle multi-project build when you start writing an application from scratch is super easy. But what if the project has already established structure? And what if the feature modules depend on each other?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*1-T-gca66m8YPZwYyCFBLw.png" /><figcaption>Example project dependency structure</figcaption></figure><p>In this setup features depend on the Core module. If I would just clone all of the repos to my hard drive and add them as local dependencies in my application project, Feature A and Feature B would still download Core module from the remote repository.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fece7ca5d0d7b4c4451384c4b869a1e/href">https://medium.com/media/9fece7ca5d0d7b4c4451384c4b869a1e/href</a></iframe><p>Of course, I could just go through the feature modules and replace all remote dependencies with local dependencies. Luckily, there’s an easier way to do that: dependency substitution. You can easily replace remote dependencies with local projects by adding a top-level instruction to the build.gradle file in the app module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e784de455f543ffcabff36cac78902b9/href">https://medium.com/media/e784de455f543ffcabff36cac78902b9/href</a></iframe><h3>Using Android Studio Git plugin with multiple repositories</h3><p>If you want to use Android Studio’s Git plugin for managing your repositories, go to `Settings -&gt; Version Control` and add your dependency directories as version control roots by selecting them and clicking `+` button below. Android Studio will now see dependency projects as git repositories and will detect changes and allow Git operations on files in dependency directories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*38paysrQuXtvOZm0yXvHtw.png" /><figcaption>Adding multiple repositories in Android Studio version control plugin</figcaption></figure><h3>TL;DR</h3><p>To set up a multi-project build on your machine:</p><ul><li>Clone relevant repositories to your hard drive.</li><li>Add project dependencies to `settings.gradle` file in the root project and specify project paths, for example:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a570bef4d8835b4875656f2cd25a5fbd/href">https://medium.com/media/a570bef4d8835b4875656f2cd25a5fbd/href</a></iframe><ul><li>In the `build.gradle` project in the `app` module add an instruction for the custom dependency resolution strategy, for example:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e784de455f543ffcabff36cac78902b9/href">https://medium.com/media/e784de455f543ffcabff36cac78902b9/href</a></iframe><ul><li>Sync the project with Gradle files. At this point the dependencies project should be visible in Android Studio’s file browser:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*mDpCcEt1dmV5Uvss_4ZZdg.png" /></figure><ul><li>(optional) If you want to use Android Studio’s version control plugin, add the dependency’s directories as version control roots in the Android Studio settings.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a5323f8680b" width="1" height="1" alt=""><hr><p><a href="https://blog.codequest.com/gradle-multi-project-build-substituting-jar-dependencies-with-local-projects-4a5323f8680b">Gradle multi project build — substituting jar dependencies with local projects</a> was originally published in <a href="https://blog.codequest.com/">codequest</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>