<?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 𝗷𝗶𝗺 on Medium]]></title>
        <description><![CDATA[Stories by 𝗷𝗶𝗺 on Medium]]></description>
        <link>https://medium.com/@jimlyas?source=rss-3b2f17bc6d4e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H9AjQBt87TjqhQGStqVXog.jpeg</url>
            <title>Stories by 𝗷𝗶𝗺 on Medium</title>
            <link>https://medium.com/@jimlyas?source=rss-3b2f17bc6d4e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:37:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jimlyas/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[Let’s Make Modularization Fun Again]]></title>
            <link>https://levelup.gitconnected.com/lets-make-modularization-fun-again-81cfbd99825d?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/81cfbd99825d</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <pubDate>Wed, 03 Dec 2025 03:36:26 GMT</pubDate>
            <atom:updated>2025-12-03T03:36:26.523Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mC-4rIJdtObb3cMz" /><figcaption>Photo by <a href="https://unsplash.com/@atomsmasher?utm_source=medium&amp;utm_medium=referral">Sandip Kalal</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>A lightweight, simple, and useful Gradle Plugin to boost your productivity!</h4><p>The term “modularization” is commonly known in Android application development. Where you can group your code into separate and smaller components or modules.</p><p>A module can represent a layer based on clean architecture, a fully fledged feature, or a wrapper and implementation for a big library, and so on. And you can make a lot of them inside your project. I have personally worked with more than 100 modules for a single codebase.</p><p>Modularization is fine and dandy. There are a lot of reasons you should try it and implement it in your project. But the more modules you have, the fewer modules you’ll use for development.</p><p>What I realize is that, during the development of a new feature or bug fixing, I rarely use or even make changes to all the modules at once. A rough percentage is:</p><ul><li>50% of the time, I’ll make changes to 1–2 modules</li><li>30% of the time, I’ll make changes to 3–4 modules</li><li>20% of the time, I’ll make changes to 5 modules or more</li></ul><p>Changes that require more than 5 modules usually are refactors that you won’t come by every day. So, I actually use less than 10% of my whole codebase when developing a feature. But the other 90% is always present, whether I need them or not. Furthermore, Gradle will include all those modules during the build task even though I don’t make changes to any of them.</p><p>So I wonder, is it possible to discard or exclude any modules that I don’t really use for my development?</p><h4>Brainstorming</h4><p>So let’s say we have project like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xOUbK-tBrws7Nnw99Q8oRQ.png" /><figcaption>module dependency graph</figcaption></figure><p>sample-a depends on sample-b and sample-c using the implementation configuration. Let’s see the task’s dependency graph to see which tasks will be triggered when we run the assemble task on sample-a.</p><pre>:sample-a:assemble<br>\--- :sample-a:jar<br>     +--- :sample-a:classes<br>     |    +--- :sample-a:compileJava<br>     |    |    +--- :sample-a:compileKotlin<br>     |    |    |    +--- :sample-a:checkKotlinGradlePluginConfigurationErrors<br>     |    |    |    +--- :sample-b:jar<br>     |    |    |    |    +--- :sample-b:classes<br>     |    |    |    |    |    +--- :sample-b:compileJava<br>     |    |    |    |    |    |    \--- :sample-b:compileKotlin<br>     |    |    |    |    |    |         \--- :sample-b:checkKotlinGradlePluginConfigurationErrors<br>     |    |    |    |    |    \--- :sample-b:processResources<br>     |    |    |    |    +--- :sample-b:compileJava *<br>     |    |    |    |    \--- :sample-b:compileKotlin *<br>     |    |    |    \--- :sample-c:jar<br>     |    |    |         +--- :sample-c:classes<br>     |    |    |         |    +--- :sample-c:compileJava<br>     |    |    |         |    |    \--- :sample-c:compileKotlin<br>     |    |    |         |    |         \--- :sample-c:checkKotlinGradlePluginConfigurationErrors<br>     |    |    |         |    \--- :sample-c:processResources<br>     |    |    |         +--- :sample-c:compileJava *<br>     |    |    |         \--- :sample-c:compileKotlin *<br>     |    |    +--- :sample-b:jar *<br>     |    |    \--- :sample-c:jar *<br>     |    \--- :sample-a:processResources<br>     +--- :sample-a:compileJava *<br>     \--- :sample-a:compileKotlin *</pre><p>We can see that sample-a’s task depends on tasks from sample-b and sample-c. But most of the time, I already know which modules I want to make changes to, and I don’t want Gradle to run any tasks from modules I don’t care about.</p><p>The thing is, an external dependency is qualified for all that. It’s part of the codebase that we will <em>(and can’t)</em> change. And because it’s already neatly packed, Gradle will not run any task from it, and just resolve any artifacts from it and provide it as an input for the intended task.</p><h4>The Idea</h4><p>I want to make include sample-b as an external dependency and not a module dependency for sample-a.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eG1W1NJjjEeuH9g3eUJdTw.png" /><figcaption>sample-b as external dependency</figcaption></figure><p>Let’s just publish all the modules to a local repository following this tutorial:</p><p><a href="https://docs.gradle.org/current/userguide/publishing_maven.html">The Maven Publish Plugin</a></p><p>I’ve published the module to a libs directory inside the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*yCh-apVj6AD4E0SsFN6hDg.png" /><figcaption>libs directory as maven repository</figcaption></figure><p>Add some configuration in settings.gradle.kts to tell Gradle to only use dependency with a groupId “io.github.jimlyas” from libs directory:</p><pre>dependencyResolutionManagement {<br>    repositories {<br>        mavenCentral()<br>        google()<br><br>        // Add this<br>        maven(&quot;${rootDir}/libs&quot;) {<br>            content {<br>                includeGroup(&quot;io.github.jimlyas&quot;)<br>            }<br>        }<br>    }<br>}</pre><p>And in sample-a’s build script, let’s just change sample-b as a dependency:</p><pre>dependencies {<br>  // Before<br>  // implementation(project(&quot;:sample-b&quot;))<br><br><br>  // After<br>  implementation(&quot;io.github.jimlyas:sample-b:0.1.0-SNAPSHOT&quot;)<br>}</pre><p>If we see the task’s graph again for sample-a’s assemble , it looks shorter:</p><pre>:sample-a:assemble<br>\--- :sample-a:jar<br>     +--- :sample-a:classes<br>     |    +--- :sample-a:compileJava<br>     |    |    +--- :sample-a:compileKotlin<br>     |    |    |    +--- :sample-a:checkKotlinGradlePluginConfigurationErrors<br>     |    |    |    \--- :sample-c:jar<br>     |    |    |         +--- :sample-c:classes<br>     |    |    |         |    +--- :sample-c:compileJava<br>     |    |    |         |    |    \--- :sample-c:compileKotlin<br>     |    |    |         |    |         \--- :sample-c:checkKotlinGradlePluginConfigurationErrors<br>     |    |    |         |    \--- :sample-c:processResources<br>     |    |    |         +--- :sample-c:compileJava *<br>     |    |    |         \--- :sample-c:compileKotlin *<br>     |    |    \--- :sample-c:jar *<br>     |    \--- :sample-a:processResources<br>     +--- :sample-a:compileJava *<br>     \--- :sample-a:compileKotlin *</pre><p>Now Gradle will not run tasks from sample-b, and the build should be faster because there are fewer tasks to run.</p><p>But using this method has several drawbacks that we can recognize, for example:</p><ul><li>It’s difficult when you want to use another module.</li><li>Changing modules must be made continuously in every build script the module is used.</li><li>What if we want to return to using a module we previously substituted? Revert the changes again?</li></ul><p>There will be many changes required, especially if you utilize a lot of modules. This clearly means we need to simplify the implementation if we want it scale well.</p><h4>The Gradle Plugin</h4><p>So I created a Gradle plugin to make it easier to do this and make it easier to use, as can be seen below:</p><p><a href="https://github.com/jimlyas/bifrost">GitHub - jimlyas/bifrost: Gradle Plugin to bridge between prebuilt artifact and local module dependency</a></p><p>This plugin doesn’t include a mechanism for releasing modules. The projects using it are free to use their own setup and configuration. Modules can be released to a local directory or to a Maven repository instance.</p><p>Next, we’ll discuss how to use this plugin in your project. You can download it from the Gradle Plugin Portal. This plugin has two components: a plugin applied in the settings script and a plugin applied in the build script.</p><p>However, before applying the plugin, we need to add the following Gradle properties:</p><pre># ...<br># Other properties<br>open.bifrost.gate=false</pre><p>Also, create a version catalog gradle/realm.versions.tomlthat will contain the modules that will be replaced with artifacts later. Create it in this format:</p><pre># You can customize version based on your own setup<br>[versions]<br>module = &quot;0.1.0-SNAPSHOT&quot; <br><br># List all your projects here<br>[libraries]<br>sample-a = { group = &quot;io.github.jimlyas&quot;, name = &quot;sample-a&quot;, version.ref = &quot;module&quot; }<br>sample-b = { group = &quot;io.github.jimlyas&quot;, name = &quot;sample-b&quot;, version.ref = &quot;module&quot; }<br>sample-c = { group = &quot;io.github.jimlas&quot;, name = &quot;sample-c&quot;, version.ref = &quot;module&quot; }<br><br># Leave it empty for now<br>[bundles]<br>active = [] </pre><blockquote>Make sure the entry name in the libraries section and the dependency name have the same value as the module name.</blockquote><p>Now we’ll apply the io.github.jimlyas.bifrost.settings plugin to settings.gradle.kts like this.</p><pre>pluginManagement {<br>    repositories {<br>        // The plugins are coming from here<br>        gradlePluginPortal()<br>        mavenCentral()<br>    }<br>}<br><br>plugin {<br>    id(&quot;io.github.jimlyas.bifrost&quot;) version &quot;&lt;LATEST VERSION&gt;&quot; // Add this <br>}<br><br>include(&quot;:always-on-module&quot;) // Module that you will always open<br><br>// Add this too<br>configure&lt;BifrostSettingExtension&gt; {<br>    // Add module that you&#39;ll change as prebuilt artifact later<br>    includeModule(&quot;:sample-a&quot;, &quot;:sample-b&quot;, &quot;:sample-c&quot;)<br>}</pre><p>Dan kita akan menerapkan plugin io.github.jimlyas.bifrost.project ke build.gradle.kts ke setiap project yang akan menggunakannya dan rubah deklarasi dependency menggunakan entri version catalog dari realm.versions.toml .</p><p>And we’ll apply the io.github.jimlyas.bifrost.project plugin to build.gradle.kts for every project that will use dependencies from realm.versions.toml and change the dependencies declaration using the version catalog entry from realm.versions.toml</p><pre>plugin {<br>    // ...<br>    // Other plugins<br>    // Add this<br>    id(&quot;io.github.jimlyas.bifrost.project&quot;)<br>}<br><br>dependencies {<br>    // Before<br>    // implementation(project(&quot;:module-b&quot;))<br>    // implementation(project(&quot;:module-c&quot;))<br><br>    // After<br>    implementation(realm.module.b)<br>    implementation(realm.module.c)<br>}</pre><h4>Let’s use it in action!</h4><p>Let’s assume we’ll only be making changes to the sample-a and sample-c modules. Therefore, we’ll use the sample-b module as an external dependency.</p><p>First, add sample-a and sample-b to realm.versions.toml.</p><pre># Update this<br>[bundles]<br>active = [&quot;sample-a&quot;, &quot;sample-b&quot;]</pre><p>Modules not defined in the active will be modified using the artifact.</p><p>Next, simply change the value of open.bifrost.gate to true.</p><pre># ...<br># Other properties<br>open.bifrost.gate=true</pre><p>Sync your Gradle project again, and it’s done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nvWn2KYkdq0abSGavjf1Og.png" /><figcaption>How it’s going to look like</figcaption></figure><p>Changes to the gradle.properties and realm.versions.toml files should not be tracked with Git. Ensure these changes are made only to your machine.</p><p>When you’re done using the plugin and want to revert to the original configuration, simply change the value of open.bifrost.gate to false and resync Gradle.</p><h4>The Result</h4><p>After completing all the setup and configuration, let’s check the impact of using this plugin on our project.</p><p>To do this, we’ll use <a href="https://github.com/gradle/gradle-profiler">Gradle Profiler</a> to measure the difference between when:</p><ul><li>The Bifrost gate is opened</li><li>And when the Bifrost gate is closed</li></ul><p>And do both scenarios by only changing two files, the gradle.properties and the realm.versinos.toml . Here is the scenario file we’ll use:</p><pre>gate_opened {<br>  title = &quot;bifrost gate is opened&quot;<br>  tasks = [&quot;:app:buildDebug&quot;]<br>  gradle-args = [&quot;-Popen.bifrost.gate=true&quot;, &quot;--rerun-tasks&quot;]<br>  warm-ups = 1<br>  iterations = 5<br>  cleanup-tasks = [&quot;clean&quot;]<br>}<br>gate_closed {<br>  title = &quot;bifrost gate is closed&quot;<br>  tasks = [&quot;:app:buildDebug&quot;]<br>  gradle-args = [&quot;-Popen.bifrost.gate=false&quot;, &quot;--rerun-tasks&quot;]<br>  warm-ups = 1<br>  iterations = 5<br>  cleanup-tasks = [&quot;clean&quot;]<br>}</pre><p>Let’s return to my own project, which has over 100 modules. Here’s a comparison between when the bifrost gate is closed and when it’s open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXoiPZJHeCzAsy_GuXpLyQ.png" /><figcaption>Gradle Profiler Result</figcaption></figure><p>The results are quite satisfactory, with an average build time reduction of ~60% when the gate is open. On the other hand, when the gate is closed, Gradle requires using all modules to build which takes longer.</p><p>Please feel free to try the Gradle plugin and leave comments and recommendations on my code. This plugin is suitable for use when you only need to focus on or be responsible for a specific module, but still require code from other modules in your build.</p><p><a href="https://plugins.gradle.org/plugin/io.github.jimlyas.bifrost">io.github.jimlyas.bifrost</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81cfbd99825d" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/lets-make-modularization-fun-again-81cfbd99825d">Let’s Make Modularization Fun Again</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualizing Compose Navigation with Kotlin Compiler Plugin]]></title>
            <link>https://proandroiddev.com/compose-diagram-e74fcbac08f8?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e74fcbac08f8</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <pubDate>Mon, 29 Sep 2025 14:39:57 GMT</pubDate>
            <atom:updated>2025-09-29T14:39:57.522Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6gIFikF7JCKZYSrv" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>From code to diagram: Leveraging Kotlin compiler plugin to generate Mermaid diagram for your app’s navigation graph</h4><blockquote>The navigation library used for writing this is type-safe navigation2, and not the latest nav3 library</blockquote><p>I’ve been developing Android applications for more than 5 years, and within those years, I’ve always been fascinated with how we navigate to other screens.</p><p>Before fragments, the application navigates between activities using startActivity with Intent class. It works well enough until fragments and the navigation component come around.</p><p>Using the navigation component, we can see which screen can navigate which screen by using the “Navigation Graph” from the XML file.</p><figure><img alt="Navigation Graph" src="https://cdn-images-1.medium.com/max/1024/0*qk7Jx7szLFaWR873.png" /><figcaption>From <a href="https://developer.android.com/guide/navigation/design/nested-graphs#example">Android Developer</a></figcaption></figure><p>From the preview tab of the XML file, we can see what screen is the start, what the next screen is going to be, and we can be redirected to open the fragment file when clicking the component.</p><p>Fast forward today, and developers are pushed to use Jetpack Compose with its own navigation library. While developing a screen with Jetpack Compose is surely more fun than with a fragment component and XML, using their navigation library personally for me is hard, especially before the type-safe navigation.</p><p>The term “navigation graph” now represents different things from the fragment era. Now it simply list the screens for this graph and what “Route” you should pass to navigate to said screen.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99d11efc3cc45e04b8edae86e1964067/href">https://medium.com/media/99d11efc3cc45e04b8edae86e1964067/href</a></iframe><p>With it, you’ll understand that to navigate to FriendsListScreen you have to pass the FriendsList instance, and so on.</p><p>There’s no actual “diagram” where you’ll be able to see things such as:</p><ul><li>Which screens are the entry point for this screen</li><li>What screens are opened from this screen?</li><li>An overview journey of the application, like storyboards from start to end</li></ul><p>Quick search with Google or prompt your favorite AI chatbot, and it will tell you there are no official “diagram” tools for compose navigation.</p><p>It made me think that perhaps it’s something I can do.</p><h3>Background</h3><p>My current project handles navigation arguments in ViewModel with SavedStateHandle . So to ease and speed up the migration from String-based navigation to type-safe navigation, we used annotation processing with KSP to automatically generate the navigation graph and the type map for non-primitive type parameters of the navigation argument.</p><p>Using KSP, the processor will:</p><ul><li>Aggregate composable functions that are annotated with a custom annotation (Route)</li><li>Collect the route class/object of the annotation parameter with the associated composable function.</li><li>Analyze the constructor parameter of the route/object to identify which parameter needs to be added to the typeMap</li><li>Generate the navigation graph that will be added to NavHost later.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c8e2f916f63317d498c735ab8950c89/href">https://medium.com/media/9c8e2f916f63317d498c735ab8950c89/href</a></iframe><p>All screens will have navAction as parameter, that basically a lambda to pass what screen will be navigated to next because the actual function that will call NavController is located at the NavHost .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9d9fd87d47e5a507c302ac723afc3bf/href">https://medium.com/media/c9d9fd87d47e5a507c302ac723afc3bf/href</a></iframe><h3>Goals</h3><p>The diagram I want to achieve is a <a href="https://mermaid.js.org/">Mermaid</a> chart because it has a simple syntax, many functionalities, and also many references and samples everywhere.</p><figure><img alt="Mermaid Chart Sample" src="https://cdn-images-1.medium.com/max/1024/1*vn098wtkYCmbEkGGNSNgHA.png" /><figcaption>Mermaid Diagram Sample</figcaption></figure><p>Let’s break down the objective:</p><ul><li>Collect all the screens; they are annotated with a custom annotation (Route) and set it as the origin.</li><li>Find where the extension function navigateTo is called and use the first parameter of it as the destination (let’s just assume navigateTo always called in the same file where the screen is).</li><li>Aggregate them together and generate the mermaid chart.</li><li>Profit (???)</li></ul><p>Sounds easy enough, right?</p><p>As you already know, my current project is already familiar with implementing annotation processing with KSP. I thought perhaps for this use case, we can also use KSP to generate the diagram.</p><p>Although KSP can do the first point mentioned before, it turns out there’s a limitation of KSP that it can’t examine expression-level information of source code (refer <a href="https://kotlinlang.org/docs/ksp-why-ksp.html#limitations">here</a>). So we can’t really do the second point of our goal.</p><figure><img alt="Meta-Programming" src="https://cdn-images-1.medium.com/max/1024/1*SDN_wSNITCdAO3ybOWuLHw.png" /><figcaption>Diagram for choosing the right meta-programming tools, from <a href="https://resources.jetbrains.com/storage/products/kotlinconf-2023/Meta-Programming%20With%20KSP%20and%20Kotlin%20Compiler%20Plugins.pdf">here</a></figcaption></figure><p>Because we need to evaluate the body of a function to locate where the extension function navigateTo is called, there’s no other choice but to write our own Kotlin compiler plugin.</p><h3>What is Kotlin Compiler Plugin</h3><p>Kotlin compiler plugins help you analyze, validate, and even add more code to your source code during compilation time.</p><p>Some of the most famous compiler plugins are <a href="https://github.com/Kotlin/kotlinx.serialization">kotlinx-serialization</a> , <a href="https://github.com/JetBrains/kotlin/tree/master/plugins/compose">Compose</a> , and even KSP is technically a compiler plugin too.</p><p>But unlike KSP, compiler plugin doesn’t well-documented which means you’ll usually guess which API will do the things you want. For example, KSP provide you with guidance of hierarchy of how they will look at the source code (refer <a href="https://kotlinlang.org/docs/ksp-overview.html#how-ksp-looks-at-source-files">here</a>) but compiler plugin doesn’t really document it anywhere (<em>per my knowledge, I could be wrong tho’</em>).</p><p>Furthermore, their API is not stable which means the API you use for your own plugin can be no longer supported in the next version or even deleted.</p><p>All of this because it’s <em>technically </em>not intended for public use<em>. </em>It is there so the compiler developer can do their job.</p><p>Nevertheless, it feels like something challenging to do and exciting to achieve our goal.</p><p>A compiler plugin commonly has two components:</p><ul><li>Gradle module, where you write the Gradle plugin that will be applied to the consumer module.</li><li>Kotlin module, where you write the actual implementation of the compiler plugin.</li></ul><figure><img alt="Kotlin Compiler Plugin Architecture" src="https://cdn-images-1.medium.com/max/1024/1*WNpbHdEydT31qvvn9s0tww.png" /><figcaption>Kotlin Compiler Plugin Structure</figcaption></figure><p>We will make every part of it including the CommandLineProcessor which is optional, it is where you can bring it external properties from consumer project to the compiler plugin. We’ll use it to define the path of generated mermaid file.</p><p>In this article, we will try to write it from the bottom (Kotlin-side) to the top (Gradle-side).</p><h3>Kotlin Module</h3><p>Create a new Kotlin module and set up the build.gradle.kts like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0001f0ef56141cf2158e902bbd231b87/href">https://medium.com/media/0001f0ef56141cf2158e902bbd231b87/href</a></iframe><p>Next, we’ll make a new class, NavDiagramVisitor that will analyze each element of our source code. If you’re familiar with KSP’s KSVisitor , it kind of looks like the same thing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85bb85c51bcfc4e039908a4c37ab1727/href">https://medium.com/media/85bb85c51bcfc4e039908a4c37ab1727/href</a></iframe><p>We must register the NavDiagramVisitor with the extension. In the extension, we will generate the file and its content for the diagram. This extension will have a string parameter to represent the file path.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b641077c13be66bfe9aae1892df8243/href">https://medium.com/media/6b641077c13be66bfe9aae1892df8243/href</a></iframe><p>Before we can put the argument to the NavDiagramGenerationExtension , we’ll have to make the key for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed038cfa7f0ece02c3ae3cc444862acf/href">https://medium.com/media/ed038cfa7f0ece02c3ae3cc444862acf/href</a></iframe><p>And now we can make the CommandLineProcessor to setup the properties from the Gradle plugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/663353473bc77def28d980085382d4b4/href">https://medium.com/media/663353473bc77def28d980085382d4b4/href</a></iframe><p>Now, let’s combine them for the CompilerPluginRegistrar . Where we will register the extension and put the output file path from the configuration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/546706bded037dcb46af01250e1a93c1/href">https://medium.com/media/546706bded037dcb46af01250e1a93c1/href</a></iframe><p>We’re very close now, we just need to set up two files inside src/main/resources/META-INF/services .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85daab169fc0d546b962b8e64b9df477/href">https://medium.com/media/85daab169fc0d546b962b8e64b9df477/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47c19688a1d515fc249e09064a63a38b/href">https://medium.com/media/47c19688a1d515fc249e09064a63a38b/href</a></iframe><h3>Gradle Module</h3><p>Create a new Kotlin module and set up the build.gradle.kts like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81451e78a76057d5683309dee825ae9f/href">https://medium.com/media/81451e78a76057d5683309dee825ae9f/href</a></iframe><p>Let’s move on to create the extension for our Gradle plugin, where the consumer’s build script will provide the output file for our generated mermaid file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa5485a39ec0b6b0c5915f28d384d2e2/href">https://medium.com/media/aa5485a39ec0b6b0c5915f28d384d2e2/href</a></iframe><p>From there, we’ll create the Gradle plugin with a new class named NavDiagramPlugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/203afce003ab927a2795f9467b02b745/href">https://medium.com/media/203afce003ab927a2795f9467b02b745/href</a></iframe><p>That’s pretty much it. Now the code part pretty much complete, we’re ready to implement it to the project.</p><h3>Result</h3><p>Now apply the Gradle plugin to the project</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3256914606a1448960beed208fdcfd60/href">https://medium.com/media/3256914606a1448960beed208fdcfd60/href</a></iframe><p>Next, every time you build the project it will generate the mermaid diagram for you in the build directory.</p><p>To open the mermaid file directly inside Android Studio, you’ll need to install Mermaid plugin here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMB3ky_KkiitfZAN0u5OJw.png" /><figcaption>Mermaid Plugin for Android Studio</figcaption></figure><p>The generated diagram should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rBu2u0JRBtEbE9y2iBQkrQ.png" /><figcaption>Generated Mermaid graph</figcaption></figure><h3>Other Resources</h3><p>You can learn more about Kotlin Compiler Plugin here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FSi0r2_N0J88%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSi0r2_N0J88&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FSi0r2_N0J88%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5209f3d53633efc6fd3a4ca4879001cc/href">https://medium.com/media/5209f3d53633efc6fd3a4ca4879001cc/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9P7qUGi5_gc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9P7qUGi5_gc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9P7qUGi5_gc%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b296522e63d980cd7a80efd7c189d43/href">https://medium.com/media/1b296522e63d980cd7a80efd7c189d43/href</a></iframe><ul><li><a href="https://github.com/Kotlin/compiler-plugin-template">GitHub - Kotlin/compiler-plugin-template</a></li><li><a href="https://github.com/bnorm/piecemeal">GitHub - bnorm/piecemeal</a></li></ul><p>To see how other developers are using the compiler API, you can explore it on Github. For example it you want to know how to use IrElementVisitorVoid, search for the term like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YPjvsi2rZz2rUdgVpr5U4w.png" /><figcaption><a href="https://github.com/search?q=IrElementVisitorVoid+language%3AKotlin+&amp;type=code">Code Search Result</a></figcaption></figure><h3>Closing Thought</h3><p>I’m not making this a library because I’m not very proud of the code. It’s just a simple idea to solve my own use case, and I just want to share my journey of writing my own compiler plugin.</p><p>But even then, I’m satisfied with how it turns out. And I’m excited about where this idea will take me.</p><p>Of course, there’s a lot of room for improvement, such as:</p><ul><li>Multi-module navigation: We can also group Route from the same module into subgraphs in the Mermaid diagram.</li><li>Additional context: Mermaid support includes text for nodes such as componentA — SampleInformation→componentB .</li><li>Support other formats like Graphviz.</li><li>Perhaps improve the code to follow the compiler standard.</li></ul><p>Please share your thoughts about it, and should I publish it and make it an actual library?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e74fcbac08f8" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/compose-diagram-e74fcbac08f8">Visualizing Compose Navigation with Kotlin Compiler Plugin</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[Using Kotlin Reflection to Automate Compose Navigation]]></title>
            <link>https://proandroiddev.com/4c5b565f660f?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c5b565f660f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[technology]]></category>
            <pubDate>Mon, 14 Oct 2024 03:52:22 GMT</pubDate>
            <atom:updated>2024-10-14T03:52:22.534Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KliIiBIVtu5aIRe-" /><figcaption>Photo by <a href="https://unsplash.com/@jordanmadrid?utm_source=medium&amp;utm_medium=referral">Jordan Madrid</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Because who got time to register parameter names and all of their typeMaps</h4><h4>The Past</h4><p>So if you like me, an Android Developer who uses Jetpack Compose daily, you probably have the same issue as me when using the navigation library.</p><p>I’m personally not so fond of the String route basis for the navigation. There’s so much to declare and remember for basic things, like the String route to associate with your Composable function, keys for each argument, and NavType for each argument.</p><p>In addition, because your route is a plain String, you need to implement a way to connect your String route to your arguments like storing it in the same class or the same package or encapsulating it in a sealed class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/406625c6e7d41b41f1c9c715a874fba0/href">https://medium.com/media/406625c6e7d41b41f1c9c715a874fba0/href</a></iframe><p>Furthermore, parameters are now will be parsed as String because, in a String-based route, all navigation arguments are treated as query parameters or paths like in a URI.</p><p>So when the new <a href="https://developer.android.com/guide/navigation/navigation-type-safety">Type Safety</a> was introduced in Compose Navigation, I was so thrilled to try it out.</p><h4>The Present</h4><p>In the new Type Safe navigation, The underlying implementation of the String-based route is still the same. But using the power of Serializer, they make it less painful than before.</p><p>Instead of registering your route as a String and using said String when navigating to another Screen, you now use Object/Class as your route. And when you need to navigate to that Screen you need to pass the instance.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/218d54d33d36cf99061508454cbade7b/href">https://medium.com/media/218d54d33d36cf99061508454cbade7b/href</a></iframe><p>Everything is all and well in the world, <em>or is it</em>?</p><p>If all of your arguments are primitive types like String, int, Boolean, etc… then you can relax and use the latest compose navigation version. But if not, perhaps you put third-party classes as your navigation argument like BigDecimal or UUID then we need to talk.</p><p>It is considered bad practice to include complex data as an argument, as mentioned here:</p><figure><img alt="warning to not pass complex data as navigation argument" src="https://cdn-images-1.medium.com/max/862/1*c5WmEHoqtNCsIJQ5nriQrg.png" /><figcaption>from Developer Android <a href="https://developer.android.com/guide/navigation/use-graph/pass-data#supported_argument_types">Documentation</a></figcaption></figure><p>But sometimes we can’t help it, either the application flow forces us to pass some data (or even a list of objects) or we are just lazy, so sometimes we want to pass the “<em>unsupported parameter</em>” type as arguments. But how to do that in the latest navigation compose library?</p><p>Let’s say we have a code like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f31602d4a8e9f373cc8351e394a0597/href">https://medium.com/media/0f31602d4a8e9f373cc8351e394a0597/href</a></iframe><p>In addition to adding annotation <a href="http://twitter.com/contextual">@contextual</a> annotation to the BigDecimal, we need to add <a href="http://twitter.com/Serializable">@Serializable</a> annotation too to the Account class. What happened when we built this code?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3SgSxCPbTwWHROAD20F6w.png" /><figcaption>IllegalStateArgumentException</figcaption></figure><p>Serializer still can’t parse the Account class as an argument, because we still have to add Custom NavType when declaring it from the composable function. So it will look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f96bf115d2706b19ad0a19d76cb68c05/href">https://medium.com/media/f96bf115d2706b19ad0a19d76cb68c05/href</a></iframe><p>You can look on the internet what the CustomNavType will be for your code, or use generic to handle it dynamically. You’ll need to add custom this NavType for the custom class.</p><p>In addition, it still can’t provide mapping for classes that we can’t add the <a href="http://twitter.com/serializer">@serializer</a> annotation to, like BigDecimal. Here’s the link to the issueTracker:</p><p><a href="https://issuetracker.google.com/issues/348468840">Google Issue Tracker</a></p><p>I don’t think there’s a workaround for that right now, so you will have to wait until the library supports it natively.</p><p>The other thing is collecting the navigation arguments can be done in two ways:</p><ul><li>From NavBackStackEntry from calling the composable function in NavGraphBuilder</li><li>From SavedStateHandle from ViewModel</li></ul><p>These TypeMaps will be used to parse your argument from String to intended type when called from NavBackStackEntry. On the other hand, when using SavedStateHandle, you need to pass the TypeMap again somehow.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35ce1185687ce35930afbe66a66116a2/href">https://medium.com/media/35ce1185687ce35930afbe66a66116a2/href</a></iframe><p>Perhaps there might be a good reason why TypeMap still needs to be re-defined from ViewModel, or maybe the SavedStateHandle can’t configure which NavType to use from the given route, or it just simply can’t access it from the current implementation.</p><p>And just like before, there’s currently no workaround if you don’t want to do that, you will have to pass your NavType again if you’re accessing your arguments from SavedStateHandle.</p><p><em>or is it?</em></p><h4>The idea</h4><p>I usually use my arguments from ViewModel and I often pass complex data as arguments, so with the latest composable navigation library I have two issues:</p><ul><li>Currently, Serializer can’t use third-party classes as arguments</li><li>I’m just too lazy to be registering NavType every time I register my route and when I want to access my arguments in ViewModel</li></ul><p>I want to make new type of abstraction or extension of the current API to fulfill my needs. I’m fully aware there are some libraries that can do that for me already, but I want to see what I’m able to make.</p><p>I want to be able to make the implementation as close as possible to the official compose navigation library but with my own spin. So this is what I came up with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*rdjUIOQXFS9NjCK72Ch-_Q.png" /><figcaption>Some Idea I’m cooking</figcaption></figure><p>Using Kotlin Reflection, Extension Function, and GSON, it is possible to do all that.</p><h4>The Implementation</h4><p>So first let’s add the dependencies what we will be using like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de20946ee3a4cfa39baa08f33dc8df7f/href">https://medium.com/media/de20946ee3a4cfa39baa08f33dc8df7f/href</a></iframe><p>And adding it to the build.gradle.kts file like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5199075a8989bb15155eab2fd4c39437/href">https://medium.com/media/5199075a8989bb15155eab2fd4c39437/href</a></iframe><p>Now we’re all set, let’s get cooking.</p><p>For dong this, we’re going to use the old plain String-based route because there’s not much we can do with the latest implementation that uses Type-Safety and Serializer.</p><p>First, let’s make the extension function to declare our route:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09a9f852bb1a7a6b816de63d7f409598/href">https://medium.com/media/09a9f852bb1a7a6b816de63d7f409598/href</a></iframe><p>From the generic type, we call :class to get the KClass that will be used for creating the route name and getting all the parameters of the KClass and registering it as the navigation arguments.</p><p>I usedprimaryConstructor.parameters to access all the parameters for the constructor in the type of KParameter. From the KParameter instance, we will use the parameter name that is registered in the KClass as the navigation argument key. Another thing we’re going to do is define the NavType from KParameter.type to know which NavType is compatible with the parameter type, and for the nullability, we can easily call Kparameter.type.isMarkedNullable to know if the parameter is nullable and the navigation argument will reflect that.</p><p>After getting all the navigation argument types, It’s time to define the route for the composable. Using buildString, we will add:</p><ul><li>The qualified name of the KClass, and shorten it to only contain three words using the asRouteName function</li><li>Add all the arguments from earlier as URI parameter type</li></ul><p>It will look something like this:</p><pre>package.name.ClassName?param1={param1}&amp;param2={param2}</pre><p>Next, we define code for navigating to another Screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/273518fe84a7f3ffc6cdaa088db6cc94/href">https://medium.com/media/273518fe84a7f3ffc6cdaa088db6cc94/href</a></iframe><p>From the generic type, we call :class to get the KClass type of route parameter.</p><p>I used URI builder to help add more parameters for the URI that will be passed to the navigation function. For the URI, I added the qualified name from KClass like before using the asRouteName function.</p><p>declaredMemberProperties will give us the parameters that we will add to the URI. Looping the parameters and accessing the parameter name and its value before adding it to the URI builder earlier.</p><p>The result URI will look like this:</p><pre>android-app://androidx.navigation/package.name.ClassName?param1=param1Value&amp;param2=param2Value</pre><blockquote>This is basically the same URI that will be passed when using the String-type route</blockquote><p>Lastly, for accessing the navigation argument the code will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b17243a70fb6cef73046a723754966c8/href">https://medium.com/media/b17243a70fb6cef73046a723754966c8/href</a></iframe><p>There are two extension functions from NavBackStackEntry and SavedStateHandle with the name getArg for simplicity. With Kotlin Reflection, it will call the primary constructor of KClass from generic.</p><p>But before calling the primary constructor, we’re going to need all the primary constructor’s parameters that we will get from the receiver of the extension function.</p><p>This code will initialize the given generic type and return the instance.</p><h4>The Result</h4><p>By making a new function composeRoute, I was able to make an abstraction of the old plain String as a route so the consumer no longer needs to do all the additional stuff that you need to do earlier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e6ad8c4a8e40b4c055dc76f284fe8a3/href">https://medium.com/media/6e6ad8c4a8e40b4c055dc76f284fe8a3/href</a></iframe><blockquote>Please don’t give too much attention to the annotation, it doesn’t really do much</blockquote><p>Navigating to another screen will look the same as the official compose navigation library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d5259bd9b4d8ae220726d41e7bffde0/href">https://medium.com/media/6d5259bd9b4d8ae220726d41e7bffde0/href</a></iframe><p>Whether you’re accessing your navigation arguments from NavBackStackEntry or SavedStateHandle, you’ll only need to call the getArg function and define which route you want to access.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2401301040ca6c9a33857bb52d826471/href">https://medium.com/media/2401301040ca6c9a33857bb52d826471/href</a></iframe><p>Using these three extensions functions, you’ll have more or less similar experience as when using the official library. In addition whether your navigation uses all primitive data types or not, nevertheless you can use this out of the box.</p><p>If you’re interested or want to deep dive more to the code, I made this as a library here:</p><p><a href="https://github.com/jimlyas/reflection-navigation">GitHub - jimlyas/reflection-navigation: Type safe Jetpack Compose Navigation through Kotlin Reflection and GSON</a></p><p>Please do check it out or try it out, and give me your comments on what do you think.</p><p>Thank for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c5b565f660f" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/4c5b565f660f">Using Kotlin Reflection to Automate Compose Navigation</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[Living Dangerously without Obfuscation]]></title>
            <link>https://proandroiddev.com/living-dangerously-without-proguard-affda698a46b?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/affda698a46b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[programming]]></category>
            <pubDate>Mon, 23 Oct 2023 01:28:33 GMT</pubDate>
            <atom:updated>2023-10-23T01:28:33.538Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jcVDiUT5IFs_irhW" /><figcaption>Photo by <a href="https://unsplash.com/@flowforfrank?utm_source=medium&amp;utm_medium=referral">Ferenc Almasi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>A story how I (seemingly) hacked an Android application from a unicorn startup</h4><h4>Background</h4><p>First and foremost, this is not a “How To” or even a step by step tutorial to hack an Android Application.</p><p>This is my journey when I started learning how important it is to implement secure coding to the project—and some takeaways that I would like to share when taking this journey.</p><p>For the context, I’m an Android application developer and I love learning all about Android development. I’ve taken some projects related to smart house and VOD platform at my previous workplace. During my time there, I caught an interest in securing Android application using obfuscation.</p><p>Because no application is safe from <a href="https://www.computerworld.com/article/2585652/reverse-engineering.html">Reverse Engineering</a>—where you can decompile an APK to its original form (decompiled .java classes), and see how it was built. There’s a saying:</p><blockquote>“Every application is open source if you know Assembly”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zPEamVtoL7PyuAprhsZi0Q.png" /><figcaption>Reverse Engineering (Oversimplification)</figcaption></figure><p>So my understanding is:</p><blockquote>“Obfuscation is a way to make it harder for people to read your code from your project when you published it.”</blockquote><p>For example, if we have this code sample in our project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60a59f7cfa2669c346be20608ae640d1/href">https://medium.com/media/60a59f7cfa2669c346be20608ae640d1/href</a></iframe><p>This chunk of code will stay this way even after being compiled into an APK. But with obfuscation, you can make your code look like this even when decompiled:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b87a706be647e21ea03285dfda70c404/href">https://medium.com/media/b87a706be647e21ea03285dfda70c404/href</a></iframe><p>Obfuscation shortens the name of classes and members, which results in reduced DEX file sizes.</p><h4>Setup</h4><p>So learning this new thing, I want to put my newfound knowledge in play. I started to reverse engineer some applications to see how secure they are and, if they’re not secure enough, how the apps were built and what libraries were used.</p><p>To achieve this, I used:</p><ul><li><a href="https://code.visualstudio.com/">Visual Studio Code</a>: IDE for opening the project and general coding</li><li><a href="https://apklab.surendrajat.xyz/">APK LAB</a>: OpenSource Android reverse-engineering Tools</li><li><a href="https://play.google.com/store/apps/details?id=cn.trinea.android.developertools.pro&amp;hl=en&amp;gl=US">Dev Tools Pro</a>: To pull APK from installed application</li></ul><p>There’s this one application that developed by a startup that got my interest. Let’s call it ABC app.</p><p>So I installed the ABC app on my device, use Dev Tools Pro to get the APK from it. Then I moved the APK to my machine, opened Visual Studio Code and ran the APK Lab to decompile the APK.</p><p>To my surprise the code was not obfuscated properly, and you can still read most of the code and learn how they work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyqYTDLgB05DxPBJi_N1Dg.png" /><figcaption>Decompiled code</figcaption></figure><p>Knowing this, I couldn’t help myself to further browse all their codebase. I learnt everything I could from their code, their infrastructure, and their libraries.</p><p><em>Aha. Libraries.</em> What libraries did they use?</p><p>After looking through their code for a while, I happened to read what seemed to be code for dependency injection. And in there, they used <a href="https://github.com/square/okhttp">OkHttp</a> and <a href="https://github.com/ChuckerTeam/chucker">Chucker</a> to log their API call. So I started wondering,</p><blockquote>“Their released application doesn’t display the Chucker log in the notification bar, but the code is there. Is it possible to display the Chucker log?”</blockquote><p>Using APK Lab, you can compile the decompiled APK to APK again (<em>So I guess </em><strong><em>reverse</em></strong><em> reverse-engineering</em>). At first, I started the changing the Java files and compiled them again into an APK. But this didn’t seem to work because there was no changes after my modification. My prediction is that the APK Lab doesn’t use the Java files to compile them into an APK again.</p><p>So I started looking at the Smali files that were decompiled along with the Java files. And if I’m being honest, I didn’t know a single thing—and still don’t know much—about Smali, let alone coding using it. But I was able to locate the Smali code where the dependency injection was added and the Chucker log is not being implemented.</p><p>There was just one small step to enable the Chucker log: Simply add the ChuckerInterceptor to OkHttp in the Smali file. So without any knowledge whatsoever, I started some trial-errors to implement that in the Smali code I found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5ThSa93jCZRiv11XvS4dw.png" /><figcaption>Final Smali code used to display Chucker Log</figcaption></figure><p>After countless errors, I thought I was starting to recognize the pattern in code for Smali. And <em>voilaaa</em>… the compiling succeeded. I ran the compiled APK from APK Lab to my device. <em>And it was there!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*IxaQYxsUfn4tphhbrmbH6A.png" /><figcaption>Chucker Log</figcaption></figure><p>Using the Chucker log, I was able to see their HTTP requests, responses, and the list of all their APIs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*K-HHqY9EFqUMX2tEqqI-EQ.png" /><figcaption>Sample Response from ABC app</figcaption></figure><h4>Conclusion</h4><p>At the time, I didn’t know how big of a security risk if something like this ever happened to a published application with thousands or even millions of active users.</p><blockquote>Update: ABC app already patch their app and doing something like this will not give the same result</blockquote><p>I strongly believe something like this should not happen in a production application published to end-users. What we can learn is:</p><ul><li>Obfuscate your code properly! You might be already obfuscating your code, but is it already hard enough to read? If you’re using ProGuard or DexGuard as your obfuscation tools, perhaps you might put too much keep configuration that can remove all the advantages that obfuscation brings. You can read <a href="https://jebware.com/blog/?p=418">this</a> for more information about differentiation in keep configuration.</li><li>Use the library properly. Chucker is very useful when developing, but should not be used in production. Using debugImplementation when declaring dependency like this is a must.</li></ul><p>Thanks for reading my story.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=affda698a46b" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/living-dangerously-without-proguard-affda698a46b">Living Dangerously without Obfuscation</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[Jetpack Compose for Late Adopters]]></title>
            <link>https://proandroiddev.com/jetpack-compose-cc59718b3914?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc59718b3914</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <pubDate>Sun, 15 May 2022 14:44:02 GMT</pubDate>
            <atom:updated>2022-05-15T14:44:02.058Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oztq262cM_V0tXHb" /><figcaption>Photo by <a href="https://unsplash.com/@edhoradic?utm_source=medium&amp;utm_medium=referral">Edho Pratama</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>For you who’s not sure about learning jetpack compose or not</h4><h3>Why not learn earlier?</h3><p>There’s this new trending library in Android application development called <strong>compose</strong>, it was announced in Google I/O 2019 more or less three years ago. Since then, it’s started growing more and more bigger and better. Many people are saying this is the end of using XML to design application in Android Application. And many tutorials made, many courses released, many libraries developed to support the ecosystem since Google released compose first stable release.</p><figure><img alt="Jetpack Compose in Action" src="https://cdn-images-1.medium.com/max/1024/1*IISZEdmR2XoyfF9-8OmxuQ.gif" /><figcaption>Jetpack Compose in action</figcaption></figure><p>When it first released, I thought to myself there’s probably still a long time for me to start using it in my own project. Because from the glance, it seems like a lot of work to migrate our current projects to start using compose. In addition for that, I myself don’t have any experience whatsoever with declarative UI and reading the documentation alone it seems there’s a lot new concept to learn. So I hesitant to start learning compose in its’ early days.</p><p>Looking back, there’s a time I started learning compose but the preview doesn’t work the same way as when you’re using XML. When you’re designing Android application using XML layout, the preview will automatically and seamlessly update in every changes you make in the file. On the other hand, using compose when you’re using preview you need to build your module and render your previews again every time you make changes. I immediately stop learning, because I tend to make so much revisions and preview is what keep me sane during designing the app.</p><p>This year, I thought to myself to start learning compose again. And I can say I’m hooked with it, even the preview issue I said earlier doesn’t seem to bother me that much anymore. When your changes is small like updating padding or width size, the preview will workout that automatically, but adding new component… not so much.</p><p>I started learning compose <a href="https://developer.android.com/courses/pathways/compose">here</a> , and let’s see what we can learn for a developer like me who’s late in the game.</p><blockquote>This is not a tutorial to use compose, but somewhat opinionated things I learned while learning compose.</blockquote><h3>Thinking in Compose</h3><h4>Imperative vs Declarative UI</h4><p>There’s a transition happening in mobile application development and it’s moving into declarative UI.</p><p>In not so distant past, Android Developers use XML to design the layout for their application. But this XML file can only contains what component inside the layout and the configuration like color or background or content. If later you need to dynamically change the content, like for example displaying fetched data from API/web service, you need to do it in your Kotlin file.</p><p>But because your design is in XML file and your code is in Kotlin so you need a way to refer your XML’s component inside your Kotlin code. There’s many ways you can do this, like:</p><ul><li>findViewById , manually refer to its’ ID</li><li><a href="https://github.com/JakeWharton/butterknife">ButterKnife</a> , create variable using annotation with the resource ID as the parameter <em>(deprecated</em>)</li><li>Kotlin synthetic, generate extra code to access your view as if they are properties with the name of your resource ID <em>(deprecated</em>)</li><li>ViewBinding / DataBinding, generate binding class for each XML layout in your module with direct reference to your component</li></ul><p>Doing it like this is called Imperative UI because you’re focus on the how the data will be displayed first. And there’s issues with it, for example where possibly when your application grow more complex, you’ll possibly need to update or configure your application in multiple places.</p><p>Declarative UI solves this problem using different approach. It focus more on the data that will be displayed. It basically means it’s fine to rebuild parts of your UI from scratch instead of modifying them, modern CPU fast enough to do so.</p><h4>Shift in thinking</h4><p>My take on this is because the code is in Kotlin you don’t need resource ID as you do when using XML, you don’t need to refer to it after you created them. But then you might freak out and ask,</p><blockquote><em>“So how do we update them later on?”</em>.</blockquote><p>Instead of changing or updating UI when application state changed, we describe how the UI is under specific conditions of state. Take a look of this code sample:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c686318c052cdb932dfec82885afb6f/href">https://medium.com/media/6c686318c052cdb932dfec82885afb6f/href</a></iframe><blockquote>If you’re familiar with Kotlin, probably code like below should be intuitive for you</blockquote><p>We have Text that display how many glass of water we had every time we click the button. So rather than update content of the Text every time the button clicked, we create a variable that contains the number of water as <strong>state </strong>and update the variable every time the Button is clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Mf16AsiasvPfz8iO.png" /><figcaption>Core UI Update Loop</figcaption></figure><p>Using image below as a reference:</p><ul><li>The event, is when the Button is clicked</li><li>Update state, is update current value of count +1</li><li>Display the state, is changing the content of the Text</li></ul><p><strong>State</strong> determines what is shown in the UI at any particular time. You can make almost anything as a state, such as basic types (String, Boolean, Int), and even resources (String, Color, Drawable, and Dimension). And when your state value is updated, any component that used it will be updated accordingly. And that is the heart of declarative UI in Jetpack Compose.</p><p>To get use to using state in your code, it will not take very much time. Later on, all your Activity code could be inside the compose function.</p><h4>Implementing it in your project</h4><p>You’re probably wondering how many changes will be made when implementing/migrating current project into using Jetpack Compose. If your project already implemented clean code architecture, there’s not much changes will be made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*ruyUD23vUAFNTo7Q.jpg" /><figcaption>Clean Code Architecture</figcaption></figure><p>Because Jetpack Compose is only a library that describe how your UI work and displayed, only your <strong>presentation layer</strong> will have to change. The rest of your code like fetching data from API, storing and manipulating data in local database, it will work as intended with Jetpack Compose.</p><p>You can even gradually migrate your code to adopt Compose because Compose and Android View work well together. More about that <a href="https://developer.android.com/jetpack/compose/interop">here</a>.</p><h3>What does it like designing in compose</h3><h4>Displaying list data</h4><p>To grasp how easy it is to use compose, let’s take a sample if we’re going to display list of data. In XML era, we’re probably going to use RecyclerView . And the steps might be as follows:</p><ul><li>Create Adapter and ViewHolder with array/list to store data inside the RecyclerView</li><li>Add RecyclerView to the XML layout</li><li>Setup RecyclerView with Layout Manager and add the adapter to it</li><li><em>(optional)</em> if your data not yet ready when the RecyclerView initialized, you’ll have to add the data to the list within the adapter to update it</li></ul><p>There’s a lot of steps need to be done just to display list of data. But using compose, because all the layout, configuration, and state are stored inside the composable function. So you don’t have to do that much stuff anymore, let’s take a look of this example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d790750a8b164980cd2949b40c383ae/href">https://medium.com/media/5d790750a8b164980cd2949b40c383ae/href</a></iframe><p>Using compose, what you can do is:</p><ul><li>No need for Layout Manager, you can define how list will be displayed by built-in layout. For example for displaying vertically use LazyColumn and for displaying horizontally use LazyRow</li><li>Create a new compose function and add the data object as the parameter, any action like click can be configured inside it</li></ul><p>And that’s it, no adapter or viewHolder needed. As you can see, using compose will actually help you write less code and you can work with less file. This reason alone make some developers eager to learn more about compose.</p><h4>ConstraintLayout</h4><p>I’m a strong believer that you’ll make better design using ConstraintLayout . Because if you’re thinking about responsive UI, using ConstraintLayout actually make sense.</p><p>At first I thought it would be difficult implementing ConstraintLayoutusing compose because we’re not using resource ID to add constraint. There’s ConstraintLayout implementation you can use by adding this to your gradle configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3750b42e4af5a9e986e825885c4701c8/href">https://medium.com/media/3750b42e4af5a9e986e825885c4701c8/href</a></iframe><p>First thing first, instead of using resource ID like designing in XML ConstraintLayout in compose using reference that you can create using createRefs() or createRefFor() . Let’s take a look at example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47e2e0a72338f573719c676017ff170e/href">https://medium.com/media/47e2e0a72338f573719c676017ff170e/href</a></iframe><p>will result UI like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjHqmFvCpAajiGEMOVblvA.png" /><figcaption>ConstaintLayout sample</figcaption></figure><h3>Navigating the application</h3><p>When starting new Android project, there’s question to answer like what architecture will we use to develop it.</p><ul><li>Does using multiple Activity still relevant?</li><li>Do we use Fragment back stack manually?</li><li>Or we implement single Activity architecture using Jetpack navigation?</li></ul><p>Nowadays, people goes toward using Navigation Component and use single Activity as container, and list of fragments as the page of the application.</p><p>There’s some issues I’m facing when using navigation Component, for example synchronizing the lifecycle of the Activity and the Fragment because they have their own lifecycle. Before using lifecycle observer, it’s quite hard to define which function run at which lifecycle when using Fragment.</p><figure><img alt="Fragment Lifecycle" src="https://cdn-images-1.medium.com/max/952/0*_RRNCwNOZu4ZX6AP.png" /><figcaption>From <a href="https://basaransuleyman.medium.com/android-activity-lifecycle-and-fragment-lifecycle-states-and-method-descriptions-136efc3c2ff3">Süleyman Başaranoğlu</a></figcaption></figure><p>Using the Navigation for compose is not the same as using Navigation Component. The difference I notice is as follows:</p><ul><li>In navigation for compose, single Activity doesn’t achieve by using list of fragments but you use the compose functions as destination</li><li>Navigation graph is not built using XML, but in Kotlin inside the compose function</li></ul><p>Let’s take a look for example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d70123b7378303def432450240510c7/href">https://medium.com/media/4d70123b7378303def432450240510c7/href</a></iframe><h3>Conclusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yrq7BLMy1u_iuf_V.gif" /><figcaption>Twitter will develop more features in Jetpack Compose</figcaption></figure><p>Twitter announces that they will develop more features using Jetpack Compose. So what about us? Should we do it too?</p><p>My overall experience so far with Compose is good, and I do believe it’s revolutionary technology. Using it will change your way of thinking when developing application, and it reduce your code too which is nice.</p><p>Developing more code in one language is a good thing too, I did say you can can create NavGraph using navigation for Compose, but you actually can already do that using Navigation Component. The plus side is using Compose, not only you can design your application using Kotlin, but your resources like styling, colors, typography, and even drawable (in Compose called ImageVector) can be written in Kotlin too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc59718b3914" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/jetpack-compose-cc59718b3914">Jetpack Compose for Late Adopters</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[6 Basic Security Tips for Android Application]]></title>
            <link>https://medium.com/telkomdev/basic-android-security-11dadf275dea?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/11dadf275dea</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <pubDate>Tue, 15 Feb 2022 07:39:42 GMT</pubDate>
            <atom:updated>2022-02-15T07:39:42.525Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Mobile Security" src="https://cdn-images-1.medium.com/max/1024/0*biDMHO3XbcWr4IdH" /><figcaption>Photo by <a href="https://unsplash.com/@vojtechbruzek?utm_source=medium&amp;utm_medium=referral">Vojtech Bruzek</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Gain your user trust by improving security in your Android Application with these simple tips</h4><h3>Why?</h3><p>Developing Android Application is hard, but it’s even harder for developing a secure Android Application. So why bother?</p><p>If you’re new to developing application, this might not be a thing that interests you. Because perhaps your current goal is only to build as good and as advance application as possible.</p><p>But as you keep learning, and involved in a bigger project and developing application that thousands of users use every day… It’s getting more risky to not improving your application’s security.</p><blockquote>You don’t want to build a billion dollar app, just to know that there’s someone else just copy-paste your work because they know how you build it.</blockquote><p>Furthermore, there’s a lot of people that their hobby is cracking application in Play Store. Either they did it in good faith or not, it’s up to us to prevent them from getting any information to keep application integrity.</p><p>With that in mind, let’s see what we can do to improve our application security!</p><h3>Obfuscation</h3><p>Maybe you’re familiar with build process that convert your project code into installable APK that run your application. Well this process can be reversed, where by given-APK using the right tool like <a href="https://github.com/skylot/jadx"><strong>JADX</strong></a><strong> </strong>you can get the project code of that APK… <em>kinda</em>. This process called Reverse Engineering.</p><figure><img alt="Compile VS Decompile" src="https://cdn-images-1.medium.com/max/1024/1*pNyNMaRrZI6zzcdW_HCZQw.png" /><figcaption>Compile VS Decompile</figcaption></figure><p>Well they can see the code, so what? What’s the problem? Well your business logic is embedded into the code. So don’t want anyone else can read and trace it.</p><p>So how do we solve this? Using Obfuscation, but what is it exactly? It’s a process to make the source code harder for human to read and to understand.</p><p>Your Android Project embedded with obfuscation tools using R8 and proguard, just set minifyEnabled to true in your build.gradle like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00c468fea40d4e154bb1d3845a3bd83d/href">https://medium.com/media/00c468fea40d4e154bb1d3845a3bd83d/href</a></iframe><p>With that, every release variant of your application will be obfuscated.</p><p>The other thing to consider is to configure the proguard, because there’s some parts you want to keep and some parts you want to obfuscate. By default, if you don’t declare anything proguard will obfuscate everything.</p><p>You can declare the configuration inside proguard-rules.pro file.</p><p>Here is the list of configuration you can use:</p><p><a href="https://www.guardsquare.com/manual/configuration/usage">ProGuard Manual: Usage | Guardsquare</a></p><p>And here iskeep configuration that you can try:</p><p><a href="https://jebware.com/blog/?p=418#:~:text=%2Dkeep%20disables%20all%20of%20ProGuard&#39;s,rename%20unused%20classes%2C%20for%20example">Distinguishing between the different ProGuard &quot;-keep&quot; directives</a></p><p>If the APK is decompiled without obfuscation, this is what it will look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f57209c0a91b0311f3b06fe88648828/href">https://medium.com/media/2f57209c0a91b0311f3b06fe88648828/href</a></iframe><p>On the other hand, if you enabled proguard this is what it will look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6a37dbd8f4c31e214ddeaf326a807ac/href">https://medium.com/media/c6a37dbd8f4c31e214ddeaf326a807ac/href</a></iframe><p>Well would you look at that… Imagine it in all of your code, it is near impossible to read how your code works.</p><p>In addition to improving your security, enabling proguard actually reduce your application size too.</p><h3>String Obfuscation</h3><p>Wait, what’s the different of it between just obfuscation? Well if you could look at the code before, there’s actually limitation of what obfuscation can do. For example, using proguard you can obfuscate:</p><ul><li>Name of class</li><li>Name of method/function</li><li>Name of parameter</li><li>Name of variable</li><li>Name of package</li></ul><p>But there’s something proguard can’t obfuscate, that is value of a variable. Although the code is obfuscated, it is still run the same function and algorithm you code it before obfuscation… just with a different name. But by changing the value of a variable it might impact your feature, so it actually a good thing proguard don’t obfuscate it.</p><p>But then, inside the value of a variable you might be store something important or confidential like base URL, or endpoint, and even API key from third-party. All of those that you don’t want other people to know and see from your application.</p><p>So how do we prevent other people to read our String value? There’s two options that I can give:</p><ul><li>Using NDK, by providing our secret key like base URL, API key, etc inside C /C++ class. The output result of the class is .so and it harder to decompile. Read more about it here:</li></ul><p><a href="https://medium.com/novumlogic/hiding-sensitive-data-in-android-app-dbd64e88224f">Hiding sensitive data in android app</a></p><ul><li>Using StringCare, By Storing your String inside XML resource file and adding an attribute hidden to each value tag. When decompiled, the String will be obfuscated and can’t be read, and only decrypted on runtime. Read more about it here:</li></ul><p><a href="https://github.com/StringCare/AndroidLibrary">GitHub - StringCare/AndroidLibrary: Android library to reveal or obfuscate strings and assets at runtime</a></p><h3>Root and Emulator Detection</h3><p>Commonly, you want your application run on real device that have not been tampered with anything for example like rooted device or emulator. Because running it in that kind of device might be dangerous. There’s no limit to what it can do to your application, your application data integrity might be compromised.</p><p>So it’s a good precaution to detect does your application running on rooted device or an emulator and handle it gracefully if it does.</p><p>There’s a lot of method to determine those things, but rather than doing it on your own… You can just use what everyone else already do that for you, like:</p><ul><li><a href="https://github.com/scottyab/rootbeer">Rootbeer </a>, Simple to use root detection</li><li><a href="https://github.com/mofneko/EmulatorDetector">EmulatorDetector</a> , Emulator detection tools</li><li><a href="https://developer.android.com/training/safetynet/attestation">SafetyNet API</a> , Anti-Abuse API that assess Android Device that run your application</li></ul><p>Of course there’s no 100% method to check does the device is rooted or not, but it’s a good precaution nonetheless.</p><h3>SharedPreference Encryption</h3><p>We love using SharedPreference to store our values locally in the device, such as access token, or credential, etc. But if your application can read it, does anyone else can? Well by default yes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/0*7V0XUYXrYz8YQG_B" /><figcaption>SharedPreference inside your directory</figcaption></figure><p>Storing a new value in SharedPreference resulting you creating a new tag in xml file inside your application directory. This xml file can be opened and the value inside can be used for bad things. If you store your api key there, well too bad for you.</p><p>What you want to do is encrypt the name and the value of those SharedPreference so it can’t be used outside of the scope of your application.</p><p>Here is some library that can do that for you:</p><ul><li><a href="https://github.com/patrickfav/armadillo">Armadillo</a> , shared preference implementation for confidential data in Android</li><li><a href="https://developer.android.com/topic/security/data#edit-shared-preferences">EncryptedSharedPreferences</a> , Wraps the SharedPreferences class and automatically encrypts keys and values using a two-scheme method</li></ul><p>So for example before using encryption, your SharedPreference will look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/affa84293fe7f4835c1a4d7e8c03d615/href">https://medium.com/media/affa84293fe7f4835c1a4d7e8c03d615/href</a></iframe><p>And after using the encryption, it would look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f247e1d62e2f0c0a8887771361ab1716/href">https://medium.com/media/f247e1d62e2f0c0a8887771361ab1716/href</a></iframe><h3>Local Database Encryption</h3><p>Either using old plain SQLite, or Room, or even Realm… Using local database is such a common feature that developers use in their application. For example if your application supports offline capabilities, you probably store some data inside local database like transaction, favorite menu, etc.</p><p>But is it safe? Does anyone else can read what I store inside local database?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*50attS_KyGY0Eu-D5pX-1Q.png" /><figcaption>Local Database inside your application directory</figcaption></figure><p>Well just like SharedPreference, you can actually access your local databases inside your application directory. And even you can pullout the database to your machine and open it with DB Explorer.</p><p>So to prevent other people to read the content of our database, Don’t forget to encrypt your database!</p><p>If you’re using Room Database or plain SQLite, you can use <a href="https://github.com/sqlcipher/android-database-sqlcipher">sqlcipher</a> to do that for you. This is sample code to do that using sqlcipcher:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd57a7662293e88de54a344527c37277/href">https://medium.com/media/bd57a7662293e88de54a344527c37277/href</a></iframe><h3>Certificate Pinning</h3><p>Forcing all of your web service to support HTTPs is a great way to secure your connection, but there’s always more that you can do. Even by using HTTPs, there’s always a threat of something like <strong>Man-In-The-Middle</strong> attack.</p><p>Man-In-The-Middle attack basically means when a hacker pretends to be the service you’re connecting and allowing them to intercept communication between your application and your service.</p><p>One of the way to solving this is Certificate Pinning or SSL Pinning. Where we validate the server certification on the client-side <em>(application</em>). And doing that in Android is pretty easy, here is three ways of SSL Pinning in Android:</p><ul><li>TrustManager , This is old-school way by using mechanism from package javax.net.ssl</li><li><a href="https://developer.android.com/training/articles/security-config">Network Security Config</a> , This solution is provided for Android API Level 24 and higher</li><li>Using Okhttp, if you’re using Okhttp for as your Android HTTP Client, there’s actually a function to pin your certificate to Okhttp class, like this:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8642ba0bbff5f3273d218e44bd51c529/href">https://medium.com/media/8642ba0bbff5f3273d218e44bd51c529/href</a></iframe><p>Obviously, there’s still so much things you still can do to improve security in your Android application. But with this 6 tips, you’re up for a great start! Keep learning!</p><p>Learn more about what you can do here:</p><p><a href="https://mobile-security.gitbook.io/mobile-security-testing-guide/overview/0x03-overview">Introduction to the Mobile Security Testing Guide</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11dadf275dea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/telkomdev/basic-android-security-11dadf275dea">6 Basic Security Tips for Android Application</a> was originally published in <a href="https://medium.com/telkomdev">TelkomDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamically Change Backend Environment in Android at Runtime]]></title>
            <link>https://medium.com/better-programming/dynamically-change-backend-environment-in-android-at-runtime-d3af9ec7391f?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3af9ec7391f</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <pubDate>Wed, 26 Jan 2022 15:08:53 GMT</pubDate>
            <atom:updated>2022-01-26T15:08:53.707Z</atom:updated>
            <content:encoded><![CDATA[<h4>Speed up your Android application development by using all environments at once</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rxt3ZKVnntlEFLoVkPTWnA.png" /><figcaption>Backend’s environment example</figcaption></figure><p>When working on big scale applications, it’s always important to separate the environments on the service. This helps us to prevent any unwanted issues that will affect the service that the end-user is using.</p><p>In the context of Android applications, usually developer use build variant or build flavor to separate the app by their back-end’s environment.</p><p>Today, we will learn how to dynamically change the backend’s environment on runtime without using build variant or build flavor .</p><h3>Libraries</h3><p>Before going any further, here are libraries that we will be using:</p><ul><li><a href="https://square.github.io/okhttp/"><strong>Okhttp</strong></a>, Http Client for Android application</li><li><a href="https://insert-koin.io/"><strong>Koin</strong></a>, Dependency Injection tools for Android application</li></ul><p>Next, please do configure your Android Application to use those two libraries before continuing.</p><h3>The Environments</h3><p>The key word that we will be using to change the environment on Android application is interceptor . But what is it actually?</p><blockquote><a href="https://square.github.io/okhttp/interceptors/">“Interceptors are a powerful mechanism that can monitor, rewrite, and retry calls.”</a></blockquote><p>Basically, by using interceptor we will change all the API call using the environment that we will define.</p><p>Let’s say we will have three environments, that is <strong>Development</strong>, <strong>Staging</strong>, and <strong>Production</strong>.</p><p>So then we will define all those three environments inside annotation class in Kotlin like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c4fb0f5ac5d3aadb1daea145e92789e/href">https://medium.com/media/7c4fb0f5ac5d3aadb1daea145e92789e/href</a></iframe><h3>Creating the interceptor</h3><p>After defining the environments that we will be using, it’s time to create the interceptor for changing base URL based on the chosen environment on the app’s runtime.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef6f09f1cc73e3c9a8d48bf230758452/href">https://medium.com/media/ef6f09f1cc73e3c9a8d48bf230758452/href</a></iframe><p>In this new class, we inherit interceptor and override its’ intercept method.</p><p>We also define a variable called env that will define which environment we will be used when calling the API. And also three other base URL for each environment.</p><p>Inside intercept method, we define a variable to use based on the chosen environment, and we will return a new request by changing the host with the base URL we define before.</p><p>We also will define another method called setEnvironment that will prompt the user to choose which environment to use for the next API call.</p><h3>Injection</h3><p>We are going to inject EnvironmentInteceptor using Koin to ensure that when the app is running, there’s only one instance of that class in our application. Doing it like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9a36f1db9af6fea7c10cf31f39de223/href">https://medium.com/media/b9a36f1db9af6fea7c10cf31f39de223/href</a></iframe><p>Add yourModule to Application class inside Koin defintion</p><h3>Implementation</h3><p>Finally, we’re going to prompt the user with the dialog we defined earlier inside EnvironmentInterceptor for defining which environment we will be using.</p><p>Call your setEnvironment before the first API call in your application. Here is an example of doing that inside SplashScreenActivity :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45576827b8fdf9a339691224ff2f4979/href">https://medium.com/media/45576827b8fdf9a339691224ff2f4979/href</a></iframe><p><em>whoosh…!! and just like that</em>, you can change the backend’s environment without building separate APKs.</p><h3>Improve Security</h3><p>Changing environment would only needed<strong> </strong>in the development phase, and this can not be released to the version of the application that end-user will be using.</p><p>How do we separate that seamlessly? we’re going to differentiate EnvironmentInterceptor for each build variant . By default, Android Project have 2 build variant , that is:</p><ul><li><strong>Debug </strong>variant of the app that we use during development</li><li><strong>Release </strong>variant of the app that we will release to the end-user</li></ul><p>So we will create two classes in a different directory. Let’s say the EnvironmentInterceptor is located at the data package. Then we will store it at:</p><pre>app\src\<strong>debug</strong>\java\&lt;PACKAGE_NAME&gt;\data\EnvironmentInterceptor.kt</pre><pre>app\src\<strong>release</strong>\java\&lt;PACKAGE_NAME&gt;\data\EnvironmentInterceptor.kt</pre><p>Move the EnvironmentInterceptor that we created earlier in debug directory. And for release<strong> </strong>directory, define the EnvironmentInterceptor like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c2ecbc73df795667a8fcb1f551e4df7/href">https://medium.com/media/5c2ecbc73df795667a8fcb1f551e4df7/href</a></iframe><p>That will make the release variant of our application will not prompt the dialog to the user and will be using an embedded environment that is already defined in the app.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3af9ec7391f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/dynamically-change-backend-environment-in-android-at-runtime-d3af9ec7391f">Dynamically Change Backend Environment in Android at Runtime</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing Harmony Application as Android Developer]]></title>
            <link>https://proandroiddev.com/harmony-bc0b3cfe3196?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc0b3cfe3196</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[huawei]]></category>
            <pubDate>Thu, 13 Jan 2022 18:22:31 GMT</pubDate>
            <atom:updated>2022-01-14T05:39:22.016Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cD-BIwo2n_po5g5j" /><figcaption>Photo by <a href="https://unsplash.com/@escuarts?utm_source=medium&amp;utm_medium=referral">Alex Escu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Developing HarmonyOS Application as Android Developer</h3><h4>Add HMS to support your android application in Huawei devices</h4><h3>Background</h3><p>As of 2019, new Huawei devices are banned from using Google services. This ban means that Huawei devices can no longer access API provided by Google like Maps API, or using Firebase as platform for developing Huawei Devices.</p><p>This doesn’t mean Huawei can no longer manufacture devices with Android Operating System because Android itself is open-source. But a year later, Huawei announced that they are releasing a new operating system called HarmonyOS for Huawei devices.</p><p>What does that mean for us as Android Developer? Do we have to support new operating system? Or how do we maintain our android application to support HarmonyOS?</p><p>Let’s learn more about it together!</p><h3>“Brand New” Operating System</h3><p>It’s safe to presume that Huawei will no longer releasing new mobile device with Android because they have their own operating system now. But developing a new operating system is hard, how do they able to do that in one year?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*kJ0WLbiMibHpBJwo2gJzDw.jpeg" /><figcaption>Android x HarmonyOS</figcaption></figure><p>Well, the easy answer is they don’t… But kinda is. So far as I can tell, it really looks like HarmonyOs is <strong>forked version of Android</strong>. HarmonyOS is built on top of AOSP (Android Open Source Project), so it have some similarities with Android OS. My company sent me HarmonyOS device to test, so I just run simple Android program on it and it works.</p><p>So my hypothesis is:</p><blockquote>Because HarmonyOS works the same as Android and basically other operating system based on AOSP. All your UI/Presentation code will work as intended in HarmonyOS devices. Things like View configuration, or Activity and Fragment , you can still use all of that.</blockquote><p>Knowing that, my goal is<strong> supporting my already-released Android Application for HarmonyOS with little modification as possible</strong>. Which basically mean, no creating new project or repo or branch <em>(in git)</em> for HarmonyOS, no downloading new software if possible.</p><p>Speaking of downloading new software, Huawei have their own IDE for developing HarmonyOS apps called HUAWEI DevEco Studio. But I’m not going to install it, but if you do… You can download it here:</p><p><a href="https://developer.harmonyos.com/en/develop/deveco-studio">HUAWEI DevEco Studio - HUAWEI HarmonyOS APP</a></p><p>Or if you’re being lazy, you can install their plugin called HMS Tookit from settings in Android Studio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eGDJT0HYrTYuh2iAXJ9yxQ.png" /><figcaption>HMS Toolkit plugin from marketplace</figcaption></figure><p>This plugin enables you to develop application using Huawei Mobile Service (HMS), and have feature like:</p><ul><li><strong>Cloud Debugging</strong>, If you don’t have Huawei device… You can reserve time to run your app in remote Huawei device</li><li><strong>Location Kit Tool</strong>, Mock location for Huawei location kit <em>(Google’s Maps API alternative)</em></li></ul><h3>Firebase Alternative</h3><p>As said in the beginning, some Firebase features might be not supported in HarmonyOS because it used Google Mobile Services. You can read more about that <a href="https://firebase.google.com/docs/android/android-play-services">here</a>.</p><p>This table represent which Firebase feature might be affected in HarmonyOS devices:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*4jiy9nwwi2S_fm1osu4CPw.png" /><figcaption>Firebase features that require Google Play Service</figcaption></figure><p>The other features like Crashlytics or Performance Monitoring should working just fine in HarmonyOS devices.</p><p>But again, how do we still accomplish the same functionality without Firebase?</p><p>It turns out Huawei also releasing platform for developing mobile and web application called AppGallery Connect. Which after some research and readin their documentation, it’s basically the same feature as Firebase but with different name.</p><p>In this table, I provided some features of Firebase and AppGallery Connect:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*Q4vKfxvOvC57Qj_hFczPUg.png" /><figcaption>Features in Google and Huawei</figcaption></figure><p>Okay, so we already know about AppGallery Connect. And now, how to start a project in there? Well, you have to register an account first for HMS console. Register your account <a href="https://id5.cloud.huawei.com/CAS/portal/userRegister/regbyemail.html">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*excOcLyuA1ud5-9H8Rlwtg.png" /><figcaption>Developer Type</figcaption></figure><p>There’s two type of developer type there:</p><ul><li><strong>Individual</strong>, if you are an indie developer</li><li><strong>Enterprise</strong>, if you are releasing the app as a company</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6tvDdL_6cXkoNQ1YterR5A.png" /><figcaption>Upload identification</figcaption></figure><p>Another things to prepare when registering a developer account is they ask you for identification like:</p><ul><li>ID Card released by the government or Driver’s license</li><li>Bank Document</li></ul><p>I don’t know why they need all of those things for registering an account, but this is the way it is. Then, it will take up to two days for them to validate your information. And only then, you can start using the feature of AppGallery Connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRGmJ2eLcvhl_a7nwLZkJQ.png" /><figcaption>AppGalleryConnect console</figcaption></figure><p>That is the console of your project. Maintaining the project will somewhat easy if you already familiar with Firebase console. Project hierarchy is not so different with Firebase where in a project you can have multiple apps registered to it.</p><p>Registering your app to your project feels familiar, like adding your SHA-256 signing, downloading a JSON file and add it to your project.</p><p>If Firebase use google-services.json , AppGallery Connect use agconnect-services.json . Just put the agconnect-services.json where you put your google-services.json.</p><h3>Implementation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*sZxlzC_URjVSeiQmc0POoQ.png" /><figcaption>Platforms supported by AppGallery Connect</figcaption></figure><p>Any feature in AppGallery Connect brings SDK to be implemented to your app project. But as we can see here, there’s different SDK for HarmonyOS and Android. What do we choose?</p><p>I predicted that we can just use the Android SDK to run in HarmonyOS. And I was right, the app will run just fine in HarmonyOS even using the Android version of the SDK.</p><p>But comes the question, how do you support two services for the same app without breaking too much changes?</p><p>Some developers use build flavor to differ it, like explained here:</p><p><a href="https://stackoverflow.com/a/61839463/13200027">Have both GMS and HMS in the project</a></p><p>But it takes too much time, because we will have to create two classes for each flavors in the same functionality. And it also mean we have to build different APKs for Android and HarmonyOS</p><p>My solution is to use abstraction and inheritance, where we can just define the functionality from the SDK in super class. And implementing in sub class separately by their services. Read more about that here:</p><p><a href="https://jimlyas.medium.com/using-both-firebase-analytics-and-huawei-analytics-kit-in-android-application-88240825c71e">Using Both Firebase Analytics and Huawei Analytics Kit in Android Application</a></p><h3>Conclusion</h3><p>Adding HMS to your Android Project is not as hard as you might think. Although navigate through the documentation and console took times, me personally took two days to understand which menu to click for the action I want.</p><p>Developing is easy because your presentation layer basically doesn’t change, the thing to consider is which Google Service used in your app and know the Huawei alternative to implement.</p><h3>Source</h3><ul><li><a href="https://www.cnet.com/tech/services-and-software/huawei-ban-timeline-detained-cfo-makes-deal-with-us-justice-department/">Huawei ban timeline: Detained CFO makes deal with US Justice Department</a></li><li><a href="https://www.gsmarena.com/huawei_announces_harmonyos_20_coming_to_smartphones_in_2021-news-45202.php">Huawei announces HarmonyOS 2.0, coming to smartphones in 2021</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc0b3cfe3196" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/harmony-bc0b3cfe3196">Developing Harmony Application as Android Developer</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[Two Developer Tools for Documenting Android Codebases]]></title>
            <link>https://medium.com/better-programming/two-developer-tools-for-documenting-android-codebases-3482bad3fb4c?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3482bad3fb4c</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[coding]]></category>
            <pubDate>Thu, 06 Jan 2022 14:47:20 GMT</pubDate>
            <atom:updated>2022-01-06T14:47:20.721Z</atom:updated>
            <content:encoded><![CDATA[<h4>Documenting an Android project is easy, or is it?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7woqLDOSjLLOFF4u" /><figcaption>Photo by <a href="https://unsplash.com/@sigmund?utm_source=medium&amp;utm_medium=referral">Sigmund</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Why?</h3><p>So I maintain my company’s codebase, which is so much fun to do but also quite difficult. It’s hard because at the start, the code is small and you can learn it in a short time. Later on, the codebase is so huge <em>(still monolith, not modular yet)</em> and it’s not getting easier to keep track all of those code.</p><p>Of course, we’re starting to modularize the codebase, but it’s making it harder for new developers from the company to contribute and improve the codebase because the code is separated into modules, and no one knows where this part of code is located unless of course the people that modularize it.</p><p>From that, I always thought documenting a project is important. Why? Because it’s leaving a <strong>legacy</strong> for developers that come after us. It’s inviting the other developers to learn from it, and it helps a lot when you’re trying to refer to your old code.</p><blockquote>“Good code documents itself”</blockquote><p>Developers throw that quote around when talking about documentation. But I still think even with the well-thought naming convention, there’s a lot of things that can not you put in naming alone like context or reasoning why the code the way it is. So don’t be shy to document your code, trust me! It works.</p><h3>KDoc</h3><p>If you keep up to date with the trend, you probably using Kotlin for developing Android applications. Just like Java, there’s also a language to document Kotlin code and it’s called <a href="https://kotlinlang.org/docs/kotlin-doc.html">KDoc</a>.</p><p>Here’s a snippet of how it’s done using KDoc:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af583ed8b25484acaeb5ffbceb6b1115/href">https://medium.com/media/af583ed8b25484acaeb5ffbceb6b1115/href</a></iframe><p>TL;DR, use annotation tag inside a comment to explain part of your code. If you already familiar with <a href="https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html">Javadoc</a>, writing KDoc is super easy… Barely an inconvenience.</p><p>The other thing you might want to do is document the packages, by creating a markdown file <em>(commonly at the root of your module)</em>. That will look something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/588839eb00f8dd7f8b6dc93e6d8173f9/href">https://medium.com/media/588839eb00f8dd7f8b6dc93e6d8173f9/href</a></iframe><h3>Dokka</h3><p>You might call it a day after documenting all of your code with KDoc, but there’s always something more that you can do. So what is <a href="https://kotlin.github.io/dokka/1.6.10/">Dokka</a>? It’s basically a documentation engine that will convert your KDoc comments into a shareable format like website or markdown file.</p><p>Here is the output format of Dokka:</p><ul><li>html , a static website that you can deploy anywhere</li><li>gfm , Github flavored Markdown</li><li>jekyll , Jekyll compatible Markdown</li><li>javadoc , looks like Javadoc and convert your Kotlin code to Java</li></ul><p>Dokka has a Gradle plugin that you can add to your Android project, more about that <a href="https://kotlin.github.io/dokka/1.6.10/user_guide/gradle/usage/">here</a>.</p><p>I’ve tried all the output, but I can say html is only one worth using for now. Initially, I really want to use gfm because my codebase documentation is using <a href="https://www.mkdocs.org/">Mkdocs</a> to convert Markdown file to static website and to deploy it.</p><p>There are things like initial configuration, infrastructure, and all of that outside of the code documentation. By writing it in Markdown, it is easier because then we can just embed the formatted KDoc using Dokka as markdown to the Mkdocs directory.</p><p>After that, Mkdocs will convert all the markdown files as a website and the code documentation will have the same behavior and look like the rest of the documentation.</p><p>But there are bugs in gfm and jekyll format that I can say it’s not worth using. For example, here is the generated markdown from Dokka:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qz0eEOgcYqGOIiLlRhXQiw.png" /><figcaption>Modules documentation</figcaption></figure><p>Did you see the problem? Well let’s take a look:</p><ul><li>The table doesn’t have the second column called Summary</li><li>The link of each module refers to the HTML file, not MD file</li></ul><p>You might say, well, It’s just two right? right?? Well, there’s another:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QcXv47vzfpLNdJy-e4XRDw.png" /><figcaption>Presentation module documentation</figcaption></figure><p>The same bug still appears in other files, and to reformat all the files is such a hassle and needs a lot of work to automate.</p><p>Furthermore, there are some Dokka features that don’t support in gfm format, like:</p><ul><li><strong>Source link</strong>, where it can link your documentation to your file in the repository. It is only supported in html format.</li><li><strong>Code highlight</strong>, there’s no Kotlin highlighting in gfm format. But it supported in htmlformat.</li></ul><p>There are some developers that <a href="https://github.com/Kotlin/dokka/pull/1967">contributed</a> for a better gfm format, but I guess their main focus now is html format.</p><p>Don’t get me wrong, their generated HTML files are actually good, that’s why I’m using it for my codebase. In the end, the code documentation looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYZ4AnT0WFtqK_S_u_Ht9g.png" /><figcaption>Sample class from the codebase’s documentation</figcaption></figure><h3>Tips</h3><p>If you’re interested in using Dokka, here are some tips from me:</p><h4>DokkaTaskPartial and DokkaMultiModuleTask</h4><p>If your project is multi-module project, try using DokkaTaskPartial and DokkaMultiModuleTask when configuring your task. Like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c692af7a5a8ff70e2effe4f5b436f78/href">https://medium.com/media/5c692af7a5a8ff70e2effe4f5b436f78/href</a></iframe><p>It helps you not<strong> </strong>define configuration for each output format, cause it automatically works for all formats.</p><h4>Overriding copyright and icon</h4><p>When using html format, probably you would change the copyright at the bottom of the website and the icon. First, add dokka-base plugin to your Android project, and configure pluginConfiguration in your build.gradle.kts module, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fceb4d94405f8b1ddf8240ef8095b1e7/href">https://medium.com/media/fceb4d94405f8b1ddf8240ef8095b1e7/href</a></iframe><blockquote>Make sure you are naming customAssets file with the same name as the automated generated asset file from Dokka.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3482bad3fb4c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/two-developer-tools-for-documenting-android-codebases-3482bad3fb4c">Two Developer Tools for Documenting Android Codebases</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Both Firebase Analytics and Huawei Analytics Kit in Android Application]]></title>
            <link>https://jimlyas.medium.com/using-both-firebase-analytics-and-huawei-analytics-kit-in-android-application-88240825c71e?source=rss-3b2f17bc6d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/88240825c71e</guid>
            <category><![CDATA[huawei-mobile-service]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[google-mobile-ser]]></category>
            <pubDate>Fri, 31 Dec 2021 02:02:53 GMT</pubDate>
            <atom:updated>2022-05-19T08:11:31.898Z</atom:updated>
            <content:encoded><![CDATA[<h4>Easy way for using two analytics tool on Android application seamlessly</h4><figure><img alt="Analytics" src="https://cdn-images-1.medium.com/max/1024/1*_Dg4Z76nSkXTV9ZdiTdUjg.jpeg" /><figcaption>Analytics for Android (?)</figcaption></figure><h3>Pendahuluan</h3><p>Using Analytics tools is an important key for developing application. Because by using it, we’re able to gain informations about our application such as:</p><ul><li>Where does our users come from or downloading our app?</li><li>How users are interacting with our application?</li><li>Which feature of the application is used the most by users?</li></ul><p>If asked what time is best for implementing analytics tool, the answer is right now! Because the more we’re delaying implementing analytics, the more information about our application will lost untracked.</p><p>Currently Huawei blocked from Google services (read more about it <a href="https://www.androidauthority.com/huawei-google-android-ban-988382/">here</a>) including analytics tool. So for us who already implementing Google Analytics and want to reach more market with Huawei, we need to implementing their analytics tool, that called HMS Analytics Kit.</p><h3><em>Library and Tools</em></h3><p>Before anything, let’s learn more about libraries and tools we will be using today:</p><ul><li><a href="https://firebase.google.com/docs/analytics/get-started?platform=android"><strong>Google Analytics</strong></a>, <em>analytics tool</em> developed by Google.</li><li><a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/android-integrating-sdk-0000001050161876"><strong>HMS Analytics Kit</strong></a>, <em>analytics tool</em> developed by Huawei.</li><li><a href="https://insert-koin.io/docs/quickstart/android"><strong>Koin</strong></a>, <em>dependency injection</em> for Android Application.</li></ul><p>Configure those three libraries to your Android Project, and we are ready for the next step.</p><h3><em>Implementation</em></h3><p>Some developers using build flavor for separate analytics tool implementation, the example for doing that here:</p><p><a href="https://stackoverflow.com/questions/59974428/have-both-gms-and-hms-in-the-project/61839463#61839463">Have both GMS and HMS in the project</a></p><p>But doing it like that have some disadvantages, such as we need to build separate APKs for each analytics tool. It also affect scaling, when we need to use build flavor for other condition, so which means we will need more build flavor .</p><p>We’re not going to use build flavor , but we will use one of Object-Oriented Programming, which is <strong>inheritance</strong>.</p><figure><img alt="Class Diagram untuk analytics" src="https://cdn-images-1.medium.com/max/1024/1*7KSOxRJp__uG3I49zF50VA.jpeg" /><figcaption>Class Diagram for Analytics Tools</figcaption></figure><h3>Super Class</h3><p>Now, let’s start by creating new class in your project like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbd072d17938af23a3213bdb393e8422/href">https://medium.com/media/bbd072d17938af23a3213bdb393e8422/href</a></iframe><p>This class defines functions that we will be inherit to its’ subclasses, such as :</p><ul><li>logEvent , function to track events that happens in the application</li><li>setUserPropety , function to add user property that we will connect to every events that occured next</li><li>setUserId , function to set id for the device. This id can be used for querying the events.</li><li>clearData , function to delete analytics data that stored on the device</li><li>instanceId , function to get unique installation id</li></ul><h3>Subclass</h3><p>After creating BaseAnalytics , we will create sub-class from it based on two analytics tools:</p><h4>GMS Analytics</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/877b0baa43645c1fc4c98eb0d34ad5b8/href">https://medium.com/media/877b0baa43645c1fc4c98eb0d34ad5b8/href</a></iframe><h4>HMS Analytics</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd79729450338f81b5628495e7bbd54d/href">https://medium.com/media/bd79729450338f81b5628495e7bbd54d/href</a></iframe><p>Those two classes are implementing functions based on separate analytics tools</p><h3>Injection</h3><p>We will inject those classes using Koin, but before that we will define extension function to define which analytics tools to use based on device capability to use Google Services in our application, like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a8f46663b7b03caada2ee392d94ce7a/href">https://medium.com/media/3a8f46663b7b03caada2ee392d94ce7a/href</a></iframe><p>Then we will define Koin Module like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bad52d06847cddc996c8a0471c03d396/href">https://medium.com/media/bad52d06847cddc996c8a0471c03d396/href</a></iframe><p>Don’t forget to add analyticsModule to your Koin Definition in Application class.</p><h3>Usage</h3><p>For usage, call BaseAnalytics where it’s needed like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2369cf9419ff5501ecad19a756b1a01b/href">https://medium.com/media/2369cf9419ff5501ecad19a756b1a01b/href</a></iframe><p>If the device support Google Service (eg: Samsung) so GMSAnalytics will be used.</p><p>On the other hand, when the device does not support Google Service (eg: Huawei) so HMSAnalytics will be used.</p><p>Here is the example to track event:</p><pre>analytics.logEvent(&quot;login&quot;,bundleOf(<br>    Pair(&quot;username&quot;,&quot;Jimly&quot;)<br>    Pair(&quot;method&quot;,&quot;indihome&quot;)<br>    )<br>)</pre><h3>Conclusion</h3><p>The advantages for doing it like this is:</p><ul><li>No need to separate project, like separate repository/branch in Git</li><li>No need to use build flavor , so there’s no need to build separate APK to run on Android and Huawei</li><li>The application will automatically define which analytics tool to use on the device</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88240825c71e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>