<?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 Daniel Gallegos Ibarra on Medium]]></title>
        <description><![CDATA[Stories by Daniel Gallegos Ibarra on Medium]]></description>
        <link>https://medium.com/@mxd4n13l0n?source=rss-fdbac9bcf4f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qqI0oKroyJHunqpn.jpg</url>
            <title>Stories by Daniel Gallegos Ibarra on Medium</title>
            <link>https://medium.com/@mxd4n13l0n?source=rss-fdbac9bcf4f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 06:20:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mxd4n13l0n/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[Raising the Bar with Android StrictMode]]></title>
            <link>https://medium.com/wizeline-mobile/raising-the-bar-with-android-strictmode-7042d8a9e67b?source=rss-fdbac9bcf4f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7042d8a9e67b</guid>
            <category><![CDATA[strict-mode]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[anr]]></category>
            <dc:creator><![CDATA[Daniel Gallegos Ibarra]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 17:41:22 GMT</pubDate>
            <atom:updated>2021-06-10T04:55:09.324Z</atom:updated>
            <content:encoded><![CDATA[<p>Every project has its own business scenarios, edge cases, and fun things to solve. Still, all of them have a similar problem: how to offer an excellent user experience to their users?</p><p>One of the things that we sometimes forget, which is tightly related to UX, is the small fragments of time that the application could be unresponsive. This is widely known as <strong>Application Not Responding (ANR) dialog</strong>. Have you experienced one of those? Maybe making a payment to your friend with your bank app and then trying to share the image to your friend? Or perhaps a splash screen that takes a long time to show the app? It doesn’t necessarily mean that you got a dialog; it could be just a perception of not having feedback when you tap or swipe on the screen.</p><figure><img alt="Woody and Buzz meme — It says &quot;ANRs, ANRs everywhere&quot;" src="https://cdn-images-1.medium.com/max/735/0*UNRREQVktr1uScvZ.jpg" /></figure><h3>StrictMode to the Rescue</h3><p>As the Android documentation says: “<a href="https://developer.android.com/reference/android/os/StrictMode">StrictMode</a> is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them.”</p><p>That being said, StrictMode can greatly help us checking if we are using the Main thread to make I/O operations. Remember that the Main thread is also known as the UI thread. When launching an app Android creates a new Linux process along with this thread, which is responsible for everything that happens onscreen. What do you think that happens if you read a SharedPreference or parse a JSON file on the main thread? That’s right: app freezes in the best scenario, or, in a worst scenario, a wild ANR appears.</p><figure><img alt="Google I/O event — an speaker with an slide showing an ANR dialog" src="https://cdn-images-1.medium.com/max/696/0*boLQ6tm0OBnC3khN.jpg" /></figure><h3>Enabling StrictMode</h3><p>I have done this typically on the onCreate() method of my custom Application class. I’m just copying and pasting the code example in <a href="https://developer.android.com/reference/android/os/StrictMode">Android Developers</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f6a23af51214d2b73f57860c2418533/href">https://medium.com/media/7f6a23af51214d2b73f57860c2418533/href</a></iframe><p>Note that DEVELOPER_MODE is just a constant that could be built maybe using a gradle.properties external flag or something similar. In some code I&#39;ve worked with this is typically by default on false, and just turned on if a developer wants the option enabled.</p><p>Let’s dive a little bit into the code above to understand what we are configuring:</p><h3>StrictMode.setThreadPolicy</h3><p>With this we will set up the policy for actions on the current thread (our main thread). This sets a thread-local variable which will be propagated across cross-process IPC calls. For this example we are detecting disk reads, disk writes, network, and log that has violations on the Logcat. Another option that I like adding is the penaltyFlashScreen() which will flash the screen if it finds any violation.</p><h3>StrictMode.setVmPolicy</h3><p>You can also set up the policy for violations on the virtual machine. In this example we are detecting that maybe a SqlLiteCursor finalized without having them closed, and objects that were not correctly closed (from java.io.Closeable). Also Logging them and making a crash if any violation is found.</p><h3>Let’s Do an Experiment!</h3><p>Let’s make a little demo of StrictMode:</p><ol><li>Create a new Application (An app with a single activity is fine).</li><li>Create your custom Application and do not forget to add it on your AndroidManifest file.</li><li>On the onCreate() method of your custom Application add the code above. Copy and paste it but without the if sentence.</li><li>Add just a button and try to add this code while on your onClick event:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6effbbe3e51a64b6a6c5f9db2bf33b32/href">https://medium.com/media/6effbbe3e51a64b6a6c5f9db2bf33b32/href</a></iframe><p>We will just increase by one each time the button is clicked.</p><p>5. Debug the app and check what happens if you tap on the button.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1d7521afa0111126b51afb6cfd9cdad/href">https://medium.com/media/d1d7521afa0111126b51afb6cfd9cdad/href</a></iframe><p>In fact when I ran the app I saw three violations in this code! Two of them when the getSharedPreferences was called, another one when we fetched the counter.</p><p>Let’s create a <a href="https://developer.android.com/reference/androidx/lifecycle/ViewModel">ViewModel</a> and use a little help from our friend named Coroutines! I’ve just dispatched the code on a IO Dispatcher, but that’s just as an example (I don’t recommend to hardcode it, otherwise you’ll end up struggling in your unit tests!)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee6835dc42e5e6a8393c7f7aa5f632fc/href">https://medium.com/media/ee6835dc42e5e6a8393c7f7aa5f632fc/href</a></iframe><p>And on our activity we will have this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e47fedcf96dca9cd486de5a065f1125/href">https://medium.com/media/1e47fedcf96dca9cd486de5a065f1125/href</a></iframe><p>Let’s run the app now. Now we don’t have any StrictMode violations! Problem solved!</p><p>In conclusion: StrictMode is a very useful tool to find problems in your code. Let’s be more strict on our code and raise the bar! Our clients will be thankful for having well-performing apps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7042d8a9e67b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/wizeline-mobile/raising-the-bar-with-android-strictmode-7042d8a9e67b">Raising the Bar with Android StrictMode</a> was originally published in <a href="https://medium.com/wizeline-mobile">Wizeline Mobile</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modularization and module name collision]]></title>
            <link>https://medium.com/@mxd4n13l0n/modularization-and-module-name-collision-e6d690d7369f?source=rss-fdbac9bcf4f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6d690d7369f</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[modularization]]></category>
            <dc:creator><![CDATA[Daniel Gallegos Ibarra]]></dc:creator>
            <pubDate>Mon, 04 Nov 2019 20:35:44 GMT</pubDate>
            <atom:updated>2021-08-26T19:22:17.732Z</atom:updated>
            <content:encoded><![CDATA[<p>We are going for modularizing our application and we are doing as package by layer and by business as well. In a recent module addition we tested in our local, pipeline went fine, so I’ve asked to run a regression test. Then a QA engineer told me the he couldn’t be able to generate the apk. A wild error appeared:</p><blockquote>More than one file was found with OS independent path ‘META-INF/database_debug.kotlin_module’</blockquote><p>Ran to check that error (never seen it before) and the usual suggestion by StackOverflow and some other engineers was to add an exclusion rule on the gradle file. But the error remains and the real problem was the following:</p><p>We were using two modules for database: One nested under a core module, and another related to an specific feature (newfeature) so the packaging imports were:</p><pre>api project(&quot;:core:database&quot;)<br>api project(&#39;:newfeature:database&#39;)</pre><p>The gradle files only had the essential skeleton. The problem was that both modules were named as database and then a module name collision was raised.</p><p>A small fix was to add a different name for the modules, so it will generate different meta files.</p><pre>android {<br>  //<br>  defaultConfig {<br>    //<br>      archivesBaseName = &quot;core-database&quot;<br>  }<br>}</pre><p>So watch out for possible module naming collisions!</p><p>Edit: after two years, gradle has changed a little bit, so here&#39;s the new way we can solve the naming collission:</p><pre>android {<br>  //<br>  compileOptions {    <br>    kotlinOptions.freeCompilerArgs += [&#39;-module-name&#39;, &quot;core-database&quot;]  <br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6d690d7369f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t forget to unmockkAll]]></title>
            <link>https://medium.com/@mxd4n13l0n/dont-forget-to-unmockkall-d2eb0ad8c4d2?source=rss-fdbac9bcf4f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2eb0ad8c4d2</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[mockk]]></category>
            <dc:creator><![CDATA[Daniel Gallegos Ibarra]]></dc:creator>
            <pubDate>Wed, 11 Sep 2019 22:55:35 GMT</pubDate>
            <atom:updated>2019-09-12T15:01:03.824Z</atom:updated>
            <content:encoded><![CDATA[<p>In a project I’m collaborating we are using <a href="https://mockk.io/">Mockk</a> and many other frameworks to do unit tests. This is a very nice framework that help us to easily mock all our components including kotlin objects and static methods. I’ve been using it for a couple of months and I do really like it for its easy usage, even more than <a href="https://site.mockito.org/">Mockito</a></p><p>Today I faced some problem:</p><p>I was requested to add unit tests to some components. Such an easy task. The code then needed to be mocked not just instances but kotlin objects as well, and some other static methods too. Such easy way to just only add:</p><pre>mockkObject(SomeKotlinObject)</pre><p>The same approach you’ll need if you need to mock some static methods from a Java class:</p><pre>mockkStatic()</pre><p>I’ve added the tests and everything was fine. Consistent tests and coverage 100%. Another happy and productive day.</p><p>Today, and just by luck of not merging my change, I did a rebase of my branch to pull all the changes. My surprise was that the CI detected that a huge amount of unit tests were failing. Looking at the errors it looks like all were related to a <em>lateinit</em> property not being initialized. Strange, isn’t it? I’ve never touch any other test that the ones I’ve added.</p><p>I’ve run them in my local and they failed. I’ve run then on the main branch and everything was fine.</p><p>That gave me an idea of what could be happening:</p><p>Running only a failing test? -&gt; PASSED<br>Running only my new tests? -&gt; PASSED<br>Running all at once? -&gt; FAILED</p><p>The Aha moment was when started reading the documentation of Mockk:</p><blockquote>To revert back use unmockkAll or unmockkObject:</blockquote><p>Many flaky tests have that behavior in common: They pass when run isolated, but fail if run along with the rest.</p><p>The takeaway for me is clear: Remember to always tearDown your methods, and remember always to reset all the conditions to make the tests deterministic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2eb0ad8c4d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>