<?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 Stefan M. on Medium]]></title>
        <description><![CDATA[Stories by Stefan M. on Medium]]></description>
        <link>https://medium.com/@stefma?source=rss-179e136461f3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wHVVxNSp_xuJokHlB7eUJQ.jpeg</url>
            <title>Stories by Stefan M. on Medium</title>
            <link>https://medium.com/@stefma?source=rss-179e136461f3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 03:50:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stefma/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[Deskilled without noticing — why I’m reconsidering the Coding Dojo]]></title>
            <link>https://stefma.medium.com/deskilled-without-noticing-why-im-reconsidering-the-coding-dojo-04a08817701f?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/04a08817701f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[developer-experience]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Mon, 16 Nov 2026 12:15:24 GMT</pubDate>
            <atom:updated>2026-11-16T12:16:10.534Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deskilled without noticing — why I’m reconsidering the Coding Dojo</h3><p>In late 2018 or even early 2019, I was first confronted with the concept of a “<a href="https://codingdojo.org/">Coding Dojo</a>”. In mid-2020, after changing jobs, I introduced the same concept to my current employer. The small Android team, which back then consisted of four developers including me, met every other Friday to practice coding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cgnmfrx05_tLAxMUwni--w.png" /><figcaption>Part of the README of the Coding Dojo repository</figcaption></figure><p>The idea behind a Coding Dojo is simple: sharpening your skills in software development, just by, you guessed it, coding. It’s not only about the task itself (“it has to be super difficult”), it’s also about getting out of your daily bubble. You explore new concepts, maybe also new libraries/frameworks, or just try out different things you don’t typically do. Not to mention that such a session builds trust among team members and fosters team building.</p><p>Unfortunately, for various reasons, our Coding Dojo vanished over the years. Several circumstances, related not only to the Android team but also to the company itself, led to demotivation among team members. The increasingly infrequent dojos suddenly stopped happening altogether.</p><p>Earlier this year (2026), we had an Android offsite to discuss our current and future team structure and how to move forward. We were discussing our sprint routines and how to improve our communication.</p><p>When we discussed whether to bring back the Coding Dojo, I remember exactly how one team member argued against it, saying something like:</p><blockquote>We have AI nowadays. Why should we continue learning in coding dojos?</blockquote><p>No offense intended toward that statement at all. Back then, I tended to agree with it. Eventually, we came to the conclusion that we would drop the Coding Dojo completely.</p><p>Fast forward to today: I almost exclusively use AI to solve the tasks I’m assigned. Recently, when someone asked me, “<em>How much do you use AI?</em>”, I answered with something like, “<em>I can’t remember the last time I wrote code myself.</em>”</p><p>I remember being somewhat proud of that. And frankly, the world is shifting. So I can be somewhat proud of this, since I’m building the skills and the foundation that “future” software engineers need to survive. Sure, it sounds a bit harsh, but that’s how I see the current situation.</p><p>Yesterday, however, I read <a href="https://newsletter.signoz.io/p/ai-isnt-replacing-sres-its-deskilling">an article</a> titled</p><blockquote>AI Isn’t Replacing SREs. It’s Deskilling Them.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pRJo9qgK0flSiRAGvz_y1w.png" /><figcaption>An image I took from the blog post</figcaption></figure><p>In a nutshell, the post argues that the more you use AI, the more you get “deskilled” in the tasks you hand over to it. This is especially bad because when AI can’t solve something on its own (and you know <a href="https://en.wikipedia.org/wiki/Murphy%27s_law">Murphy’s Law</a>, right?), you have to jump in and fix it “manually”. But because you get deskilled over time, you’re likely unable to fix those kinds of cases yourself. The author also mentions that it’s not only about SREs, but a general “industry” problem. She just works as a site reliability engineer, so she maps it onto them.</p><p>Anyway, while reading it, my first reaction was something like:<br>“<em>Wow, another obvious blog post about AI.</em>”</p><p>But one sentence hit me hard and got me thinking:</p><blockquote>The more you let the system handle, the worse you get at handling things yourself and here’s the truly dangerous part, <strong>you don’t feel it happening</strong>.</blockquote><p>You don’t feel it happening: the more often you use AI for your job, the more you get deskilled in it. Slowly, but steadily.</p><p>On the one hand, this might be a “good thing”, because you no longer have to use your brain (and thus energy) for the obvious tasks. You can focus on the more complex ones. But… can you? This is the other side of the coin. You will then use AI for the complex tasks as well, hoping that it works there too. Given my experience so far, AI is able to handle complex tasks, and it keeps getting better at them. But it’s still far from a perfect solution on the first run. I still have to review the code, adjust it to our code style, correct the implementation, or even fix bugs sometimes.</p><p>Given my more than a decade of experience, those things are easy for me to handle. Still, the software development industry never stops. Just look at the JavaScript guys (sorry, these days it’s TypeScript guys): every day a new framework pops up, and of course it needs to be introduced into the codebase, because it’s obviously the new silver bullet that solves everything.</p><p>Joke aside, you get the gist.</p><p>All of this has made me reconsider the Coding Dojo. Maybe such a format is exactly the right tool to make you stand out in the age of “AI takes over software engineering jobs”. Maybe it’s the right meeting or tool to sharpen your skills, so you can easily jump in when AI reaches its limits. Maybe it’s even important for increasing communication between team members, because nowadays they only type to AI and ask it for help instead of asking a teammate, who would probably also benefit from these questions, because teaching something also helps you learn it in depth.</p><p>Maybe I should introduce it again.</p><p>Maybe… Maybe not.</p><p>Maybe the AI era is here to replace us developers at some point, completely… One thing is for sure: I will definitely find out, and I will be part of it. Somehow. One way or the other.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=04a08817701f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Speculative Decoding Explained for Laymen]]></title>
            <link>https://stefma.medium.com/speculative-decoding-explained-for-laymen-b41298de5604?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b41298de5604</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Mon, 11 May 2026 14:54:37 GMT</pubDate>
            <atom:updated>2026-05-11T14:54:37.080Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2hUIQx3IF1uVLSx6ZBvKLQ.png" /><figcaption>Abstract AI-generated visualization of token generation in a language model</figcaption></figure><p>Recently, Google updated its Gemma 4 models. <br>The announcement can be read in <a href="https://blog.google/innovation-and-ai/technology/developers-tools/multi-token-prediction-gemma-4/">this blog post</a>.</p><p>When I first read it, I didn’t really get it. <br>But along with the blog, they also published a more technical <a href="https://x.com/googlegemma/status/2051694045869879749">post on X</a>.</p><p>But my curiosity was sparked, and I really wanted to figure out what they actually changed. So, to get my head around it, I decided to write this blog to understand what the change — speculative decoding — really is. How it works, what benefits it has, and why it might not be an improvement for your specific task anyway.</p><p>Let’s explore this together from a bird’s-eye view so that even laymen understand it. So, let’s go!</p><p>Large Language Models (LLMs), by default, generate one token at a time. I won’t go into detail about what a token really is. Just assume it is <em>a word</em> or maybe even just <em>parts of a word</em>.</p><p>Take an example. The input is:</p><blockquote>Why is the sky</blockquote><p>When an LLM runs inference, the part where it generates the next token, it spits out blue.</p><p>LLMs are autoregressive, meaning they run “in a loop” — again and again — until a special “End of Sequence” token is generated. So after this first inference run, they take Why is the sky blue as input and, based on this, generate the next token. This time it generated ?. Running a third time, and it generates The. We just assume that the final output will be:</p><blockquote>Why is the sky <strong>blue? The sky appears blue because […]</strong></blockquote><p>While Why is the sky is the original user input. <br>All the following tokens are generated by the LLM.</p><p>This is, in a nutshell, how a Language Model works.</p><p>What is the enhancement in Gemma 4, which this blog post is all about?</p><p>In simple terms, they put a smaller model (named “drafter”) before each inference run to predict the next tokens.</p><p>Taking the example from above. Your input is Why is the sky. The drafter now puts, let’s say, three additional tokens to the input:<br>blue, ?, is.<br>The last prediction is “wrong”, right? <br>Keep this in mind! We will get back to this later.</p><p>The larger LLM doesn’t receive only Why is the sky (your user input), but Why is the sky blue? is.</p><p>Now you need to know that LLMs do not generate <em>the last token only</em> when running inference. Instead, they generate the next token for each token sequence — in parallel. So, on a single inference run, it will predict the next word for</p><ul><li>Why is the sky</li><li>Why is the sky <strong>blue</strong></li><li>Why is the sky <strong>blue?</strong></li><li>Why is the sky <strong>blue? is</strong></li></ul><p>Again, all of this in parallel. In a single run.</p><p>After this <em>single inference</em> run, the model only has to check (verify) each <em>generated output</em> if it matches the <em>predicted output</em> from the drafter:</p><ul><li>Is blue correct? -&gt; Yes -&gt; Keep it</li><li>Is ? correct? -&gt; Yes -&gt; Keep it</li><li>Is is correct? -&gt; No -&gt; Discard it and replace with The</li></ul><p><strong>Done</strong></p><p>Let us compare the inference run count:<br>In the world <strong>without</strong> a drafter, it has to run inference three times to get</p><blockquote>Why is the sky <strong>blue? The</strong></blockquote><p>For blue, ?, and The.</p><p>In the world <strong>with</strong> a drafter, it has to run inference only once to get the exact same output!</p><p>In short, we save two inference runs. <br>This not only saves time but also real money.</p><p>This whole technique I described here is called <strong>Speculative Decoding</strong>. Basically, the smaller model (the drafter) <em>tries</em> to predict a few more tokens, based on the user input.</p><p>The drafter needs to be small enough to be fast enough to produce a few tokens before the larger LLM starts generating the first word, but at the same time smart enough to predict the <em>correct</em> words!</p><p>You might wonder why we need a drafter at all. Couldn’t we just add random tokens to any input? The random tokens can then be just “replaced” by the LLM. The idea behind it: We generate more tokens with one inference run. Sounds smart, right?</p><p>Hold on, Sherlock.</p><p>The problem with that approach is that the LLM would run inference, generating the next token, on a false assumption and thus, generate false output as well!</p><p>Take the example from above, but change the drafter prediction:</p><blockquote><strong>Input: </strong>Why is the sky<br><strong>Drafter: </strong>Keyboard, Star, Dog</blockquote><p>The LLM would run inference with these inputs:</p><ul><li>Why is the sky</li><li>Why is the sky <strong>Keyboard</strong></li><li>Why is the sky <strong>Keyboard Star</strong></li><li>Why is the sky <strong>Keyboard Star Dog</strong></li></ul><p>It will generate the <strong>next token</strong> for all of these inputs. Since <strong>Keyboard</strong> is already wrong, the inference run on Why is the Keyboard (to predict the next token for that input) builds already on a wrong foundation! So if the input is already wrong, the output is probably wrong as well.</p><p>How to avoid this, then? <br>As soon as the model detects a wrong drafter prediction token, it will “discard” the wrong token as well as all following tokens.</p><p>Therefore, in our example here, it will just output Why is the sky <strong>blue</strong>. Not more. The generated tokens from the [..] Keyboard, [..] Keyboard Star, and [..] Keyboard Star Dog will be just discarded. So, we get the same output for a single inference run as if we were running without a drafter at all.</p><p>With that information, we can conclude that this technique is only as good as the drafter model is.</p><p>I hope I can write this down so that it is understandable even for a layman like me. I at least had fun exploring this topic. I find this technique very clever and fascinating.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b41298de5604" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase Cloud Functions and the bazillion other services that power it]]></title>
            <link>https://stefma.medium.com/firebase-cloud-functions-and-the-bazillion-other-services-that-power-it-d7645261b912?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7645261b912</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Mon, 20 Apr 2026 09:52:03 GMT</pubDate>
            <atom:updated>2026-04-20T09:52:03.342Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re a mobile developer and want to build an app yourself, you probably reach a point where you realize that you need some sort of backend. That’s exactly where I found myself with my recent idea.</p><p>While I would judge my backend skills above average, and have even implemented some backends on <a href="https://vercel.com/">Vercel</a> in <a href="https://go.dev/">Go</a> in the past, this time I decided to go all in on <a href="https://firebase.google.com/">Firebase</a>.</p><p>I don’t want to focus on learning or exploring new things. Instead, I finally want to build something that I can actually finish. I can only finish something when I use a software stack I’m familiar with, without getting stuck in endless hours of exploring new things. While it’s generally fun and I really enjoy such journeys, I always end up with a half-baked product. This time, it should be different.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*Wsa0m-uC_VPnSVa2.jpg" /><figcaption>Comic by commitstrip. Source: <a href="https://www.commitstrip.com/en/2014/11/25/west-side-project-story/">https://www.commitstrip.com/en/2014/11/25/west-side-project-story</a></figcaption></figure><p>The irony of this blog post: I wouldn’t have written it if I had only used software that I’m 100% familiar with. While I’m familiar with the concept of “Functions”, I’ve never used <a href="https://firebase.google.com/docs/functions">Firebase Cloud Functions</a> (FCF).</p><p>Anyway, while the FCF documentation has a section about “<a href="https://firebase.google.com/docs/functions#how_does_it_work">How does it work? — Lifecycle of a background function</a>” that includes some information on which services are used, I was still a bit shocked by what it’s actually using behind the scenes when deploying a function.</p><p>I like to know how stuff works and where my resources are located. This is especially true in this case, because using FCF requires you to upgrade to the <a href="https://firebase.google.com/pricing">Blaze — pay as you go — plan</a>. So when it comes to your own money, you probably want to know even more which services are used and when they actually incur cost for you.</p><p>This blog is about demystifying what <a href="https://cloud.google.com/">Google Cloud Platform</a> (GCP) services are used when creating and deploying a “simple” function on FCF.</p><p>Starting with a quick overview of “Cloud Functions” in general. Obviously, to execute your functions, some software and hardware around it are required. While, for example, Vercel hides this concept from you, it is pretty visible on FCF. I don’t know what I like more, honestly. But judging that is not what this blog is about.</p><p>Anyway, to execute a function, you need to:</p><ol><li>Have a running server (“hardware”)</li><li>Compile the code, depending on the language</li><li>Have a web server that locates your function and executes it</li></ol><p>The question now is: how does this work on GCP?</p><p>It’s good to know that all Firebase projects <strong>are</strong> GCP projects as well! There is no difference. If I understand it correctly, a Firebase project is basically a GCP project with just Firebase APIs and services enabled. So the first thing to know here, if you don’t already know it, is that you can also see your Firebase project in the <a href="https://console.cloud.google.com/">Google Cloud Console</a>.</p><p>With that said, you literally have the freedom to enable and use any GCP services within your Firebase project. And GCP has a lot more to offer than Firebase. And the Cloud Functions feature from Firebase makes exact use of this.</p><h4><a href="https://cloud.google.com/storage">Google Cloud Storage</a></h4><p>When deploying a function, FCF zips your code and saves it in a “special” Cloud Storage bucket prefixed with gcf. After deploying, you can explore the <a href="https://console.cloud.google.com/storage/browser/">bucket here</a>.</p><p>This is used to, well, store your function’s source code.</p><h4><a href="https://cloud.google.com/build">Google Cloud Build</a></h4><p>To package your function into a web server, it uses Cloud Build as a continuous delivery server. Cloud Run is somehow triggered when you deploy your function using the Cloud Storage zip file as the source. You can find the Cloud Build runs <a href="https://console.cloud.google.com/cloud-build/builds">here</a>.</p><p>What’s interesting is that when you explore the logs, you can see that it’s pulling Docker images from various places to get things done. For example, the <a href="https://console.cloud.google.com/artifacts/docker/serverless-runtimes/europe-west1/utilities/gcs-fetcher">gcs-fetcher image</a> or the <a href="https://console.cloud.google.com/artifacts/docker/serverless-runtimes/europe-west1/google-22-full/builder%2Fpython/">builder/python image</a>. The first is obviously used to fetch Google Cloud Storage (gcs) data (our function source code), while the latter is probably the “web server” part.</p><p>Also noteworthy is that it doesn’t build a binary. Instead, it creates a Docker image and…</p><h4><a href="https://cloud.google.com/artifact-registry/">Google Artifact Registry</a></h4><p>Deploy the image to the Artifact Registry. Generally speaking, the Artifact Registry is a package manager for all your artifacts. It can be used to store several types of things. In this case, it stores the Docker image created in the previous step, which now contains a complete web app including your function, ready to be executed when needed. The image can be found <a href="https://console.cloud.google.com/artifacts">here</a> inside the gcf-artifacts repository.</p><h4><a href="https://cloud.google.com/run">Google Cloud Run</a></h4><p>The last piece of the puzzle is Cloud Run. According to their documentation, the service can be used “to develop frontend and backend services”. You can deploy any Docker image there. Alternatively, you can deploy source code directly, which will be wrapped into a Docker image and executed as a container. If you go the latter route, it will probably follow the same round trip as FCF.</p><p>Speaking of FCF, it takes the image from the Artifact Registry and runs it as a container when the function is invoked.</p><p>Your Cloud Run services can be found <a href="https://console.cloud.google.com/run/services">here</a>.</p><h4>Bonus: <a href="https://cloud.google.com/security/products/secret-manager">Google Secret Manager</a></h4><p>I had an LLM write the Python function I deployed. The code contained a <a href="https://firebase.google.com/docs/reference/functions/2nd-gen/python/firebase_functions.params">SecretParam</a>, which turns out to be part of a “password manager” for GCP — Secret Manager. It is probably deeply integrated into other GCP services as well, and therefore also into FCF.</p><p>You can simply <a href="https://docs.cloud.google.com/secret-manager/docs/creating-and-accessing-secrets#create-a-secret">create a key-value pair</a> via the <a href="https://firebase.google.com/docs/cli">Firebase CLI</a>, for example, store it in the Secret Manager, and have it be read by your function.</p><p>These are probably all GCP services that are needed and used to provide a Firebase Cloud Function. Each of them provides a monthly free quota, so you likely won’t be charged while exploring functions. You can check which services offer what for free <a href="https://docs.cloud.google.com/free/docs/free-cloud-features#free-tier-usage-limits">here</a> or <a href="http://cloud.google.com/free">here</a>.</p><p>However, all the <a href="https://console.cloud.google.com/apis/dashboard">APIs and services</a> are automatically enabled as soon as you deploy an FCF. As mentioned above, you have to be in the Blaze plan to use them. So even though there are free quotas for literally all services, you still have to provide a <a href="https://docs.cloud.google.com/billing/docs">billing account</a> and have to “fear” that you make a mistake and then pay for it. Just think about an endless loop in your function that keeps calling itself over and over.</p><p>There are, of course, some things you can set up to get notified about the current pricing. But as far as I know, there’s no way to say “If the cost hits more than X [Currency]/Month, shut down all services”. Which is a bit odd.</p><p>I hope this gave you some insight into what happens behind the scenes when using Firebase Cloud Functions. It was a bit surprising to me how many Google Cloud Platform services are actually used to power them. Since it required me to upgrade to the Blaze plan, I was also a bit worried about pricing and potential costs. I’m always a little uneasy when things get automatically enabled, because I fear side effects that I don’t yet fully understand or can’t easily observe. That was one of the reasons I wrote this post. On the other hand, I now have a better understanding of some GCP services that I want to look into at some point anyway 😅.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7645261b912" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CompositionLocal in Jetpack Compose]]></title>
            <link>https://stefma.medium.com/compositionlocal-in-jetpack-compose-96c4052874eb?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/96c4052874eb</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Thu, 19 Mar 2026 12:47:14 GMT</pubDate>
            <atom:updated>2026-03-19T12:47:14.461Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBM6t1R9pbzDQuUra6UHqA.jpeg" /></figure><p>I’ve been using <a href="https://developer.android.com/compose">Jetpack Compose</a> for quite some time already. Although I occasionally use <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/package-summary#LocalContext()">LocalContext</a> or related APIs, such as <a href="https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/package-summary#LocalResources()">LocalResources</a>, and have read blogs about <a href="https://developer.android.com/reference/kotlin/androidx/compose/runtime/CompositionLocal">CompositionLocal</a>, I never fully understood how it works.</p><p>Recently, I took some time to experiment and finally got my head around it.</p><p>In this blog, I will show you some examples from my playground that helped me understand how it works.</p><p>Like me, you’re probably using LocalContext quite often. Even though it’s not recommended to get strings from it and you should use LocalResources instead, there are still plenty of cases in your code where you need our beloved <a href="https://en.wikipedia.org/wiki/God_object">God object</a> <a href="https://developer.android.com/reference/android/content/Context">Context</a>.</p><p>But how are Context or Resources actually being provided?</p><p>To answer this question, let’s quickly recap how Compose works with a simple example:</p><pre>@Composable<br>fun Greeting(<br>    analytics: Analytics,<br>    modifier: Modifier = Modifier<br>) {<br>    analytics.trackEvent(&quot;Greeting (Re)composed&quot;)<br>    Text(<br>        modifier = modifier,<br>        text = &quot;Hello World!&quot;<br>    )<br>}</pre><p>Basically, you have to pass properties — such as the Analytics object in this case — to a composable function so they can be used. Additionally, the Compose runtime can detect when a property changes and, if so, recompose the function to make use of the updated value.</p><p>I won’t go into more detail here; I’ll just assume you’re familiar with how this works.</p><p>With LocalContext, this is different, right? Somehow, you don’t have to pass the Context to the composable function, you can just get it from… “somewhere”?!</p><p>This is exactly what CompositionLocal is designed for. You can access “anything” in a composable function without providing it as a parameter. All the other benefits of the Composable runtime remain intact. So if the Context changes for whatever reason, the composable function will also be recomposed. Just as if it had been provided as a parameter.</p><p>Let me demonstrate how it works with an example. We’ll create our own LocalAnalytics, so we no longer have to pass it as a parameter to the function.</p><p>Let’s start with the updated Greeting composable, which no longer requires Analytics to be passed as a parameter:</p><pre>@Composable<br>fun Greeting(modifier: Modifier = Modifier) {<br>    val analytics = LocalAnalytics.current<br>    analytics.trackEvent(&quot;Greeting (Re)composed&quot;)<br>    Text(<br>        modifier = modifier,<br>        text = &quot;Hello World!&quot;<br>    )<br>}</pre><p>In this composable, we use LocalAnalytics to track events whenever the composable is composed or recomposed.</p><p>Analytics itself is just a simple data class that takes an Analytics.Provider and has a trackEvent function to send the given eventName to the respective Provider:</p><pre>data class Analytics(private val provider: Provider) {<br><br>    sealed interface Provider {<br>        object LogCat : Provider<br>        object Println : Provider<br>        object Firebase : Provider<br>    }<br>    <br>    fun trackEvent(eventName: String) {<br>        when (provider) {<br>            Provider.LogCat -&gt; println(&quot;Debug: LogCat - Tracking event: $eventName&quot;)<br>            Provider.Println -&gt; println(&quot;Debug: Println - Tracking event: $eventName&quot;)<br>            Provider.Firebase -&gt; println(&quot;Debug: Firebase - Tracking event: $eventName&quot;)<br>        }<br>    }<br>}</pre><p>To create LocalAnalytics, we can use of the <a href="https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#compositionLocalOf(androidx.compose.runtime.SnapshotMutationPolicy,kotlin.Function0)">compositionLocalOf</a> function, which takes a default value:</p><pre>val LocalAnalytics = compositionLocalOf { Analytics(Analytics.Provider.Println) }</pre><p>At this point, we <em>could </em>already use the LocalAnalytics inside our Greeting composeable, but it would always give us the default Analytics.Provider.Println. Most likely, we want to use the <em>current</em> provided tracking provider, which might differ from the default.</p><p>To correctly provide an Analytics instance with LocalAnalytics, we need to wrap the Greeting composable from the caller composable into a <a href="https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#CompositionLocalProvider(kotlin.Array,kotlin.Function0)">CompositionLocalProvider</a>:</p><pre>var analyticsProvider by remember { mutableStateOf&lt;Analytics.Provider&gt;(Analytics.Provider.Firebase) }<br>CompositionLocalProvider(LocalAnalytics provides Analytics(analyticsProvider)) {<br>    Greeting()<br>}</pre><p>At this point, we provide an Analytics object other than the default, using Analytics.Provider.Firebase instead of Analytics.Provider.Println.</p><p>The full source code can also be found in this <a href="https://gist.github.com/StefMa/a9d27ab56e19e4ab4bc1a505d4c46a62#file-example-kt">GitHub Gist</a>.</p><p>“<em>But how is this different from a singleton?</em>” I asked myself after writing this. Making Analytics a singleton, as the following code demonstrates, would solve the same problem, right?</p><pre>object Analytics {<br><br>    lateinit var provider: Provider<br>    /** The rest of the original code */<br>}</pre><p>Instead of providing the Analytics implementation through a CompositionLocalProvider, I can just assign a value to the provider property and use it in the Greeting composable as before.</p><p>It’s exactly the same thing, but without Compose involved.<br>So, why not go this way?</p><blockquote>Ignoring the fact that singletons are also sometimes considered an <a href="https://stackoverflow.com/questions/12755539/why-is-singleton-considered-an-anti-pattern">anti-pattern</a>.</blockquote><p>After a bit of research, I figured out two main (and important) reasons:</p><ol><li>As I mentioned earlier, Local* properties are tracked by the Compose runtime in the same way as parameters in a composable function. So if a value changes and is tracked as a composable <a href="https://developer.android.com/reference/kotlin/androidx/compose/runtime/State">State</a> object, all readers of it will automatically be recomposed.</li><li>This is probably the main argument. You can “override” the provided value (the Local* properties) at any time in your view hierarchy. This is likely why the naming convention <strong>Local</strong> was chosen. You can nest as many as CompositionLocalProvider as you want, providing different Local*.current values to their consumers.</li></ol><p>To demonstrate the first case, let’s introduce radio buttons that allow changing the Analytics.Provider at runtime in <em>another composable</em> than Greeting:</p><pre>var analyticsProvider by remember { mutableStateOf&lt;Analytics.Provider&gt;(Analytics.Provider.Println) }<br>CompositionLocalProvider(LocalAnalytics provides AnalyticsTracking(analyticsProvider)) {<br>    Column {<br>        RadioButton(<br>            text = &quot;Println&quot;,<br>            selected = analyticsProvider is Analytics.Provider.Println,<br>            onClick = { analyticsProvider = Analytics.Provider.Println }<br>        )<br>        RadioButton(<br>            text = &quot;LogCat&quot;,<br>            selected = analyticsProvider is Analytics.Provider.LogCat,<br>            onClick = { analyticsProvider = Analytics.Provider.LogCat }<br>        )<br>        RadioButton(<br>            text = &quot;Firebase&quot;,<br>            selected = analyticsProvider is Analytics.Provider.Firebase,<br>            onClick = { analyticsProvider = Analytics.Provider.Firebase }<br>        )<br><br>        Greeting()<br>    }<br>}</pre><p>Don’t get confused by RadioButton. It’s nothing fancy. Just a simple wrapper around the <a href="https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary#RadioButton(kotlin.Boolean,kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.RadioButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource)">material3.RadioButton</a>:</p><pre>@Composable<br>private fun RadioButton(<br>    text: String,<br>    selected: Boolean,<br>    onClick: () -&gt; Unit,<br>) {<br>    Row {<br>        androidx.compose.material3.RadioButton(<br>            selected = selected,<br>            onClick = onClick<br>        )<br>        Text(<br>            text = text,<br>            modifier = Modifier<br>                .padding(start = 8.dp)<br>                .align(Alignment.CenterVertically)<br>        )<br>    }<br>}</pre><p>So, what is the code doing? Each time a RadioButton is selected, the analyticsProvider changes, and so does the Analytics instance. Since this is tracked via the CompositionLocalProvider, any reader of LocalAnalytics.current will be notified of the change, and our Greeting function will recompose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b5zHuOtnpl4a-ulejUdElw.gif" /></figure><p>To explain the second case, imagine you want to track a button click. The click event should be named based on the location in the view hierarchy, so you know exactly <em>where</em> a button was clicked. The tracking event name would then be something like view1_view2_viewN_buttonClick.</p><p>The simple approach is to figure out where the button is located and name the event accordingly. But this is fragile. What happens if you move composables around or remove an intermediate view? Will you remember updating the tracking name? Or what if the button is a reusable component, hidden somewhere in a composable library in your Gradle build? Do you really want to pass the event name as a parameter? No, you don’t 😉</p><p>The solution with CompositionLocal is to “stack” them. You can simply create another Analytics instance, provide it, and wrap your button in it.</p><p>With this approach, your button, whether it’s in your current view or comes from a common composable library, doesn’t need the Analytics instance or the event name passed to it. The button itself doesn’t need to be changed. Ever. It simply takes the last provided Analytics instance via LocalAnalytics.current and tracks the event with the generic event name buttonClick.</p><p>Generally speaking, the Local*.current property will always return the “last provided” (some may also call it “nearest provided”) object in the view hierarchy.</p><p>The following example shows you how this could be implemented:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9f4b323ced9c764dd11abfa54652c02/href">https://medium.com/media/b9f4b323ced9c764dd11abfa54652c02/href</a></iframe><p>Both cases I described can’t be done easily with a singleton, not to mention other problems a singleton may introduce.</p><p>That’s it! I hope this blog helped you to understand LocalComposition a bit better. The examples shown here, as well as writing this blog, helped me finally understand it. If you’re still struggling, don’t be discouraged. Just start playing around with it. Create your own samples, and at some point, it will click, just like it did for me. 😉</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96c4052874eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aiir — our small AI experiment that didn’t work out]]></title>
            <link>https://stefma.medium.com/aiir-our-small-ai-experiment-that-didnt-work-out-9a05f5446df7?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a05f5446df7</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ollama]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Fri, 06 Feb 2026 14:18:11 GMT</pubDate>
            <atom:updated>2026-02-06T14:18:11.457Z</atom:updated>
            <content:encoded><![CDATA[<h3>Aiir — our small AI experiment that didn’t work out</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wlL5223ZujOceujlxAo0kg.jpeg" /></figure><p>Today, at <a href="https://ioki.com/">ioki</a>’s Android <a href="https://codingdojo.org/">coding dojo</a>, we tried to use an LLM to summarize why our CI (GitHub Action) was failing.</p><p>Basically, we just glued a bunch of existing CLI tools together into a new one. 😅</p><h4>How does it work?</h4><ol><li>./aiir [PR_NUMBER]</li><li>Using gh (the official <a href="https://cli.github.com/">GitHub CLI</a>), it fetches the <a href="https://cli.github.com/manual/gh_pr_checks">checks</a> for the given PR number and looks for jobs in the FAILURE state</li><li>It then fetches the logs from each failed job via <a href="https://cli.github.com/manual/gh_run_view">gh run view</a></li><li>Finally, it sends the logs — together with a prompt — to <a href="https://ollama.com/">ollama run</a></li></ol><p>The tool expects both gh and ollama to be installed. <br>Additionally, gh needs to be aware of the git remote, so it’s best to place and run the tool inside the git repository.</p><p>Our results with qwen3:0.4b, qwen3:4b, and qwen3:8b? <strong>Pretty bad! 😂</strong></p><p>The LLM output was cluttered with CI warnings and other unrelated “problems”. While the real <em>errors</em> were <em>mentioned</em>, they got lost in the sheer amount of unrelated text. In our tests, we knew why the CI failed. But if you don’t, the output isn’t helpful at all.</p><h4>What was the greater goal of that experiment?</h4><p>We hoped the LLM would give us a helpful summary of the CI errors, which we could then pass further to the <a href="https://github.com/features/copilot/cli">GitHub Copilot CLI</a> to fix them for us. 😳</p><p>But since the first step didn’t work as expected — and we also ran out of time — we stopped there.</p><p>If you want to play around with it, or even improve it, you can find the aiir code here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fadeaa7373cedf11215b6f319cdddf1f/href">https://medium.com/media/fadeaa7373cedf11215b6f319cdddf1f/href</a></iframe><h4>Nerdy details</h4><ol><li>The name aiir stands for <strong>A</strong>rtificial <strong>I</strong>ntelligence <strong>I</strong>ssue <strong>R</strong>eporter — clever, right? 😉</li><li>After we figured out how to approach it, we used GitHub Copilot’s Agent mode (GPT 4.1) to write the entire codebase. We didn’t touch or change a single line</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a05f5446df7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we broke our (push) notifications thanks to a concurrency bug]]></title>
            <link>https://stefma.medium.com/how-we-broke-our-push-notifications-thanks-to-a-concurrency-bug-6b51c1c8ec39?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b51c1c8ec39</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Fri, 02 Jan 2026 12:13:21 GMT</pubDate>
            <atom:updated>2026-01-02T15:32:21.147Z</atom:updated>
            <content:encoded><![CDATA[<h3>How a concurrency bug broke our push notifications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*vzUxesc6k1JBs_Xu7PHTlw.png" /></figure><p>Sending push notifications to users is a common task in every Android and iOS app, as it is for our app. The notifications are not encrypted for us, meaning our backend just sends clear text to the Firebase Cloud Messaging servers, and at some point, those clear text messages will be delivered to the users’ the mobile phones.</p><p>At the time, we weren’t sending sensitive data, and since no one had questioned the implementation for a long time, it seemed fine.</p><p>This changed in May 2025. Our data privacy consultant asked us developers, if we encrypt the push notification data. Multiple developers were involved in the group, and obviously, we answered no.</p><p>While we defined it as acceptable, even from a data privacy perspective, we all agreed that we actually should and want to encrypt those messages. Just for the sake of correctness. It just feels more right to do so.</p><p>Since we decided, we want to tackle this, the ticket was discussed in our backlog grooming meeting. We came up with two different solutions:</p><ol><li>Encrypting the data we sent</li><li>Sending only an ID and fetching the message from the backend on demand</li></ol><p>Eventually, we decided to go with the encryption solution. Mainly because the core logic has been in place for more than six years. We already encrypt and decrypt vehicle positions. We decided to basically just reuse the existing code and “only” move some classes and files around.</p><p>This was also why we estimated it could be implemented relatively quickly. Likely in one sprint, at most two. For us, that meant two to four weeks.</p><p>All teams were involved in this topic:</p><ul><li>iOS, written in Swift</li><li>Android, written in Kotlin</li><li>Driver (iOS and Android), written in React Native</li><li>Backend, written in Ruby</li></ul><p>The Android team merged the first client-side changes on July 24th, 2025. <br>Unfortunately, it would take until early February 2026 to finish this story.</p><p>Why this took so long, the problems we faced, and how we solved them are all covered in this blog post.</p><blockquote><strong>Note:</strong> I write this blog from the perspective of an Android developer and owner of this story, since I was the primary driver behind this feature.</blockquote><p>The (Android) pull request looked clean. It mostly involved moving classes around, renaming files, and the decryptor moved to a shared library. With that, we were able to decrypt the encrypted vehicle positions as well as push notifications.</p><p>We had tests in place, and two other developers checked not only the code but also ran an end-to-end test. Our QA Engineer tested it as well. Everything seemed to be working. And honestly, why shouldn’t it? We’ve had the same piece of code in production for more than half a decade.</p><p>We shipped it.</p><p>Thanks to staged rollouts, 30% of our lucky users benefited from…</p><pre>AEADBadTagException<br>if this Cipher object is decrypting in an AEAD mode (such as GCM/CCM), <br>and the received authentication tag does not match the calculated value</pre><p>So we got crashes. At first glance, they looked random. We didn’t know where they were coming from and why. Since none of us are cryptography experts, we first had to dig in and understand what was actually going on.</p><blockquote><strong>Sidekick</strong>: We are using AES/GCM/NoPadding for encryption. This involves an initialization vector (iv), a tag, the encrypted message, and a decryption key. Without going into details on how it works, you need all of these building blocks to decrypt the message.</blockquote><p>We immediately stopped the rollout and got in touch with our backend team. Our crash reporting didn’t provide a clear picture of what was wrong or which specific users were affected. The only thing we found was that, for some reason, the tag was incorrect. So it sounded like a backend bug?</p><p>For more aggressive testing, we got a huge list of real-world data from the backend team. It covered many different scenarios: different users, thus different encryption keys, different messages, and so on. We tested each and every item in that list. All of them worked. So, not a backend bug?</p><p>We decided to disable this feature on the backend in production, keep it running in our staging environment, and tell the other teams (iOS &amp; Driver) to halt the implementation until we find what was wrong.</p><p>Date: August 6th.</p><p>What sounded like a good solution at first was, in retrospect, not the best idea. Because we, the Android team, developed the feature in a non-backward-compatible way. Our code is expected to receive a push notification that contains a iv and a tag. If those were not present, we omitted the message, thus not posting the notification to the phone’s status bar.</p><p>Since we didn’t think about this case at the time, and because our staging system still sent encrypted notifications, we thought everything was fine so far. User got their unencrypted notifications again, we increased the release to 100%, and we could focus on solving the bug.</p><p>But this was not correct. Disabling this feature basically disabled all push notifications for users who updated to the latest version.</p><p>To find out more about this issue, we implemented a fallback service. This was basically the second solution we discussed, but decided not to go with for several reasons.</p><p>This is how it works in a nutshell:</p><ul><li>We receive an encrypted notification</li><li>We try to decrypt it</li><li>If it fails, we read the notification ID</li><li>We use the ID and do an API call to receive the message</li><li>We post the notification to the user</li></ul><p>Since the backend disabled the original feature, the previously used single flag supports_encrypted_notifications was ignored.</p><p>From now on, two flags (supports_encrypted_notifications <strong>and</strong> supports_fetching_notifications) need to be sent to inform the backend to send encrypted notifications.</p><p>Together with a bunch of client-side logs, we shipped the new version.</p><p>Date: August 21st.</p><p>At this point, thanks to the working fallback service, our users received encrypted notifications again. With the fallback service kicking in if decryption failed.</p><p>So far, so good. Now we could relax a bit, continue observing the problem, and calmly investigate to find the root cause.</p><p>Unfortunately, the initial logs we added didn’t help at all. We needed another release to add more meaningful logs.</p><p>Date: October 16th.</p><p>Two weeks later, on October 29th, we finally found the root cause of this problem. To explain this, I have to go a bit deeper into the world of Kotlin. But no worries, I still try to keep it as simple as possible.</p><p><strong>The Firebase Cloud Messaging Receiver<br></strong>To receive messages via FCM, you have to register a single FirebaseMessagingService in your application.</p><p>Since it is only possible to declare one instance of this service class, but for various reasons we need “more than that”, we introduced the concept of FirebaseCloudMessagingReceivers. It’s just an interface that can be implemented to handle incoming notifications. The single FirebaseMessagingService will then broadcast the incoming message to those Receivers.</p><p>This is the single FirebaseMessagingService:</p><pre>internal class FcmMessagingService : FirebaseMessagingService() {<br><br>    private val messagingReceivers get() = FcmMessagingReceiverComponent.instance.fcmMessagingReceivers()<br><br>    override fun onMessageReceived(message: RemoteMessage) = <br>        messagingReceivers.forEach { it.onMessageReceived(message) }<br>}</pre><p>These are our FireabseCloudMessagingReceivers:</p><pre>public interface FirebaseCloudMessagingReceiver {<br>    public fun onMessageReceived(message: RemoteMessage)<br>}<br><br>public class MyReceiver : FirebaseCloudMessagingReceiver {<br>    public fun onMessageReceived(message: RemoteMessage) {<br>        // Decrypt the message and push to the status bar<br>    }<br>}</pre><p>In our pull request, we added Kotlin Coroutine support for these. This was mainly driven by the fact that the decryption part requires the decryption key, which might be fetched on demand from our backend.</p><p>The changes looked like this:</p><pre>internal class FcmMessagingService : FirebaseMessagingService() {<br><br>    private val scope = CoroutineScope(Dispatchers.Default + SupervisorJob())<br><br>    private val messagingReceivers get() = FcmMessagingReceiverComponent.instance.fcmMessagingReceivers()<br><br>    override fun onMessageReceived(message: RemoteMessage) = messagingReceivers.forEach {<br>        scope.launch { it.onMessageReceived(message) }<br>    }<br><br>    override fun onDestroy() {<br>        scope.cancel()<br>        super.onDestroy()<br>    }<br>}</pre><p>Our FirebaseCloudMessagingReceiver simply added the suspend keyword to be able to run jobs concurrently. Our receiver, which can decrypt incoming messages now, looks like this:</p><pre>public class MyReceiver(<br>    private val decrypter: Decrypter<br>) : FirebaseCloudMessagingReceiver {<br>    public suspend fun onMessageReceived(message: RemoteMessage) {<br>        // Derypt the message and push to the status bar<br>    }<br>}</pre><p><strong>The Decrypter Class<br></strong>Our class that decrypts the messages looked like this:</p><pre>internal class Decrypter {<br><br>    val cipher = Cipher.getInstance(&quot;AES/GCM/NoPadding&quot;)<br><br>    override fun invoke(iv: String, tag: String, encryptionKey: String, encrypted: String): String {<br>        cipher.init(<br>            Cipher.DECRYPT_MODE,<br>            makeKey(encryptionKey),<br>            GCMParameterSpec(TAG_LENGTH_BYTES, iv.base64Decoded),<br>        )<br>        val encryptedMessage = cipher.doFinal(encrypted.base64Decoded + tag.base64Decoded)<br>        return String(encryptedMessage)<br>    }</pre><p>To explain all the code above in words, the following happens:</p><ul><li>The FirebaseCloudMessagingService is called by Android</li><li>Our service creates a CoroutineScope and dispatches the receiving message to each of our FirebaseCloudMessagingReceiver</li><li>One of our receivers uses the Decrypter as a parameter to decrypt the incoming message</li></ul><p>Sounds solid, doesn’t it?</p><p>If you look closely, and are familiar with Kotlin (and read the blog carefully 😉), you might have already spotted the bug.</p><p><strong>Revealing the bug<br></strong>Imagine the FirebaseCloudMessagingService.onMessageReceived method is called twice by Android, for example, because the first message was delayed by the system.</p><p>We then call our receiver twice in two different coroutines, which ends up running in two different threads!</p><p>In this case, our single receiver, using the same instance of theDecrypter, calls theDecrypter.invoke() twice from different threads.</p><p>The Decrypter, however, holds a state of the Cipher! And Cipher is not thread-safe. We are calling two methods on the Cipher init and doFinal.</p><p>If the “first thread” calls init with some data, and the “second thread” overrides that data by calling init with obviously different data, we get a crash or exception if the “first thread” calls doFinal. At that point, the Cipher holds the init-data from the “second thread”, which no longer matches the “first thread’s” init-data.</p><p>A classical concurrency, aka race condition, bug 🐛!</p><p>One solution to fix this bug is to make our Decrypter stateless by moving the Cipher.getInstant() call into the Decrypter.invoke() function.</p><p>With this approach, each call — even from two different coroutines or threads — creates a new Cipher instance. Eliminating any shared state.</p><p>The Android bug was fixed on October 29th. <br>We pushed it to production a day later.</p><p><strong>Why did it still take until February to finally close the original story?<br></strong>Initially, we went with a single flag, supports_encrypted_notifications. As soon as a client sent this, the backend knew that it could encrypt the messages for this specific user.</p><p>When the Android bug appeared, the other teams (iOS and Driver) halted their implementation because at this point, it was unclear whether the issue was on the backend or Android side.</p><p>After we found out that it was an Android bug and finally fixed it, we unfortunately forgot to tell the other teams that it had been resolved, and they could continue working on that feature. For four or five weeks, nothing actually happened.</p><p>But this was not the only reason for the delay.</p><p>When the Android team introduced the fallback service, the backend added a second flag supports_fetching_notifications. The backend would send encrypted notifications only when both flags were available; otherwise, notifications stayed unencrypted.</p><p>However, this flag was only meant as a band-aid to help find the bug. Nobody wanted it in the codebase unless it was truly necessary. As it turned out, it wasn’t!</p><p>But the backend couldn’t simply remove it and rely only on the supports_encrypted_notifications flag, because there might still be Android clients running outdated versions that send only this single flag (and not supports_fetching_notifications). Those clients should still receive notifications in clear text, unencrypted!</p><blockquote>Remember what I wrote earlier: Those users wouldn’t receive notifications at all. The Android client ignores those notifications because it requires certain properties in the payload. But encrypted ones might crash the app. <br>So what is worse?</blockquote><p>Luckily, we have a force-update behaviour in place. As soon as a user opens the app and their current version is lower than the required one, we show an “update required” screen and don’t let them use the app anymore. We decided that we wanted to make use of that. But not “today”. First, we wanted to give all users a bit of time to update on their own, since the force-update behaviour isn’t the greatest for the user experience.</p><p>As it was already early December and the Christmas season was approaching, we decided to postpone this to mid-January 2026.</p><p>Around this time, we gave users the chance to either update manually or, if they were lazy, be forced to update the App. They had about two weeks until early February. At that point, the backend was planned to switch back to the original implementation, ignoring supports_fetching_notifications and relying solely on supports_encrypted_notifications.</p><p>The other teams, iOS and Driver, finished their implementations of the feature as originally planned, using a single flag, in December. Even if they released an update earlier, users wouldn’t receive encrypted notifications. However, the clients already sent the single flag, and once the backend logic was flipped, all of them would receive encrypted notifications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b51c1c8ec39" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ETag caching with OkHttp]]></title>
            <link>https://stefma.medium.com/etag-caching-with-okhttp-7b37e494e9e8?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b37e494e9e8</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Mon, 18 Nov 2024 07:30:27 GMT</pubDate>
            <atom:updated>2024-11-18T07:30:27.173Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JE4WqaBGh_4JdCHKqu6PSg.png" /><figcaption>Obviously created by AI</figcaption></figure><p>Recently, a discussion arose that our app startup time <em>felt</em> slow. Our first guess was that this was due to the “big” /bootstrap endpoint that we call on every app start. However, someone mentioned that our app uses ETags. Without knowing the technical details about that, we know that matching ETags should omit the content body of the HTTP response, thus speeding up HTTP responses. And the /bootstrap content is not supposed to change that often.</p><p>Since everything was a bit fuzzy, we decided to dig deeper into this topic to investigate in it. Luckily, I was the one in charge.</p><p>In this blog, I wanted to share my findings not only with my colleagues but with the world.</p><h4>Basics</h4><h4>Response</h4><p>Servers may include the ETag header in the response. The ETag value can be any valid ASCII character. However, it is typically a hash of the (response) content.</p><p>There is also a special syntax for <em>weak</em> ETags. If an ETag is determined to be <em>weak</em>, then the header value should be prefixed with W/.</p><p>Examples:</p><pre># Stable ETag<br>ETag: &quot;0123456789&quot;<br># Weak ETag<br>Etag: W/&quot;0123456789&quot;</pre><p>A <em>weak</em> ETag is described as having the same semantic content, but it is not byte identical. Nevertheless, <em>weak</em> ETags can be used for caching purposes.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag">Check out the MDN website for more.</a></p><h4>Request</h4><p>If clients receive a header with an ETag, and they have the ability to cache the content, subsequent requests on the same endpoint can include an If-Non-Match header with the ETag value as the value.</p><p>The server can validate the content and, if nothing has changed, return a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304">304 Not Modified</a>. The content will be omitted from the response.</p><p>Example:</p><pre>curl -I -H &quot;If-None-Match: W/\&quot;b710206e3486741a412bc5c23df17f80\&quot;&quot; https://[SomeWhere.com]/api/passenger/user</pre><p>In this case, the ETag value is W/”b710206e3486741a412bc5c23df17f80”. If this value matches with the previous ETag header value you received from the server, and the content on that endpoint hasn’t changed, the response from this curl command should show you a 304 (status code).</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match">Check out the MDN website for more.</a></p><h4>OkHttp</h4><p>In our Android app, we use <a href="https://github.com/square/okhttp">OkHttp</a> to make HTTP calls. In debug mode we log every single HTTP call to logcat, using the <a href="https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor">HttpLoggingInterceptor</a>.</p><p>OkHttp has ETag support out of the box. You just have to enable caching by calling client.cache(). The library will do the rest for you.</p><p>While inspecting various API calls, I noticed that the server always responds with a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200">200 OK</a>. I was expecting a 304 because no one has actually changed this user in the meantime.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*Z2xJor1PBudonsqeBZrN5A.png" /></figure><p>My second attempt was to use the <a href="https://developer.android.com/studio/debug/network-profiler">Android Studio Network Inspector</a>. And indeed, here I noticed that all the requests returned a 304.</p><p>After some research, I found out that there are two types of Interceptors in OkHttp. The application interceptors and the network interceptors. Check out the <a href="https://square.github.io/okhttp/features/interceptors/">product website</a> to see their differences in detail.</p><p>However, we have added the HttpLoggingInterceptor as an application interceptor. This one omits the output of ETags. It is even mentioned in the docs:</p><blockquote>Observe the application’s original intent. Unconcerned with OkHttp-injected headers like If-None-Match.</blockquote><p>Adding the HttpLoggingInterceptor to the network interceptors would also show the correct response code in logcat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*m6Im5KiKBf15aEsB8MRatA.png" /></figure><blockquote><strong>Note:</strong> This is not a general call to add the HttpLoggingInterceptor to the network interceptors❗️It was just an observation that I wanted to share with you.</blockquote><p>Still here? Great. Thanks for reading!</p><p>If you’re curious if the slow app startup time was caused by the /bootstrap endpoint, I can tell you: No, it wasn’t. Even such a “big JSON” (~110 KB) takes “only” 250ms - 500ms on an emulator running on a 120MB/s WLAN-connected laptop. Sure, it is not fast, but it is definitely not slow.</p><p>Since this is not the cause of the problem, we may have to look into other issues a bit more 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b37e494e9e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stay Curious and Play — My attempt to make use of generative AI at work]]></title>
            <link>https://stefma.medium.com/stay-curious-and-play-my-attempt-to-make-use-of-generative-ai-at-work-d674e23c5e67?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d674e23c5e67</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[workplace]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Fri, 18 Oct 2024 12:33:40 GMT</pubDate>
            <atom:updated>2024-10-18T12:33:40.261Z</atom:updated>
            <content:encoded><![CDATA[<h3>Stay Curious and Play — My attempt to make use of generative AI at work</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*wevJ627sb777H1w8.png" /></figure><p>I’m by far not the hype-driven type (anymore). In general, I don’t use new tools or “things” just because they are hyped. However, I have to admit that I have fallen in love with generative AI since OpenAI announced its first(?) public product: ChatGPT. It felt like magic to me that a computer — let’s face it, it’s nothing more than a software program running on a computer — could generate answers (regardless of the quality) when you type in a question. I still remember the first week after I signed up for it. I spent hours asking ChatGPT how generative AI worked. Always keeping in mind that it might not be 100% correct. But still, it was good enough for someone who didn’t know anything about it. Of course, more follow-up research was needed. But at least it gave me a first glimpse of how things worked.</p><p>In short, I like generative AI.<br>So does a colleague of mine.</p><p>In the beginning, we only discussed this “new thing” from time to time. That changed at our annual company conference, BeeCon. He proposed the topic of having a <a href="https://en.wikipedia.org/wiki/Community_of_practice">Community of Practice</a> (CoP) for AI. Not knowing what we would do there and how it would end. But that was the start for me to explore AI a little bit more in detail. I even went to an AI meetup and gave a talk (<a href="https://speakerdeck.com/stefma/summaraizer-lessons-learned-along-the-way">slides</a> — just the basics, don’t expect anything fancy here). Yes, as an Android Developer.</p><p>I came up with an idea for the CoP after I suddenly got an email from an internal (support) ticket (GitHub issue) that mentioned me and already had +30 comments at that time. I scrolled through the ticket to get the gist. I replied with a more general answer — not knowing exactly what these people had discussed before and why I was mentioned in the first place.</p><p>Afterwards, I felt a little bit bad because I didn’t answer “in a good way”. But at the same time, I was also not in the mood to read all of those comments.</p><p>So suddenly my brain started working. It was juggling with <em>a lot comments</em>, <em>GitHub issues</em>, <em>GitHub API</em>, <em>generative AI</em>, <em>ChatGPT</em>, <em>OpenAI API</em>, <em>…</em></p><p>What if… what if you could type a comment on a GitHub issue like <br><em>“AI summarize please”</em>, and after some time “AI commented” back on that issue with a summary of the discussion?</p><p>Would that be possible? <strong>Hell yes, it is!</strong></p><p>So I proposed the idea in our PoC. Of course, privacy concerns were raised. We shouldn’t expose all our internal/private comments to a public AI provider. We’re probably exposing things that shouldn’t be exposed. And you really don’t know what these providers will do with that input. Yes, we’re Germans, we don’t trust ToC anyway and the claim in there “<em>we won’t use your data to train LLMs</em>” doesn’t help either. So OpenAI (and siblings like Antrophic, Gemini, Mistral, you name it) are out. Luckily, we already had a running server with Ollama installed.</p><blockquote><strong>Note</strong>: <a href="https://ollama.com/">Ollama</a> is a software to run <a href="https://ollama.com/library">some AI models</a> locally (or on a server) on your own hardware. So things will never get out of <strong>your</strong> hands.</blockquote><p>Since people come in all shapes and different sizes and therefore use software in different ways, we decided to split up our software into two parts. The “core” summarizer, which handles both “fetching GitHub issues” and “communicating with Ollama”, and a GitHub Action that would handle the communication with GitHub. Like listening to the AI trigger and commenting back on the issue — using the core summarizer to do that.</p><p>Once we had our first core prototype, which also consists of a CLI, we thought we could adapt it to support GitLab too (we use GitHub and GitLab at work, don’t ask why). I realized that the code was already quite adaptable to support more “sources”. So I quickly added GitLab as a possible source for comments. While we are on the subject, we also use Slack. Can we add Slack (threads) as a source for comments? Sure we can. Even Reddit threads can be supported. So we did.</p><p>Since we support multiple input sources (GitHub, GitLab, Slack, etc.), wouldn’t it be great to support also multiple AI providers as well? Besides Ollama, we also wanted to support OpenAI, Anthropic (Claude), Google (Gemini), and so on. Yes, we are not allowed to use the latter at work, but as an <a href="https://github.com/StefmMa">open source enthusiast</a>, I wanted to publish it on GitHub anyway. Maybe someone else is allowed to use it. Or maybe I want to use it for non-work related stuff.</p><p>With that <strong>summaraizer</strong> was born.</p><p><a href="https://github.com/ioki-mobility/summaraizer">GitHub - ioki-mobility/summaraizer: Summarizes comments from a variety of sources, such as GitHub issues, Slack threads, Reddit posts, and more using AI models from different providers, such as Ollama, OpenAI, and more.</a></p><p>Its sibling project, <strong>summaraizer-action</strong>, is just a thin wrapper around the <strong>summaraizer</strong>. It can be used in your GitHub Action workflow to handle the communication between GitHub and the <strong>summaraizer</strong>. Only a few lines of code are required to use it:</p><pre>- name: Summarize<br>  uses: ioki-mobility/summaraizer-action@main<br>  with:<br>    provider: &#39;ollama&#39;<br>    provider-args: &#39;--url https://ollama.example.com --model llama3.2&#39;</pre><p>A full example can be found on the repos README.</p><p><a href="https://github.com/ioki-mobility/summaraizer-action">GitHub - ioki-mobility/summaraizer-action: A GitHub Action that summarize GitHub issue (or pull request) comments.</a></p><p>Today, almost all of our GitHub repositories (android, ios, bugs, backlog, pit-backlog) at work can make use of it. The actions are set up and ready to go. All it takes is a single comment — <em>AI summarize please</em> — is needed to create a non-deterministic summary of the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*XkHttV_lngJxZ-wI7ZNHlQ.png" /></figure><p>I’m currently actively working on these projects. I’m looking forward to your feedback. Contributions are of course also welcome.</p><p>Oh, and before you go, two more things:</p><ol><li>There is also a <a href="https://github.com/ioki-mobility/summaraizer-slack"><strong>summaraizer-slack</strong></a><strong> </strong>project. You might want to check it out as well!</li><li>Did you know that you can <a href="https://stackoverflow.com/a/78539440">run Ollama in GitHub Actions</a>? If you don’t want to pay for an AI provider (hint: Gemini has a free tier), you might want to use this information somehow!</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d674e23c5e67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unveiling the Reality: My Experiment with Non-Transitive R Classes and Compilation Avoidance]]></title>
            <link>https://stefma.medium.com/unveiling-the-reality-my-experiment-with-non-transitive-r-classes-and-compilation-avoidance-6296922db40f?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6296922db40f</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[gradle]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Fri, 16 Feb 2024 14:20:33 GMT</pubDate>
            <atom:updated>2024-02-16T14:20:33.493Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_oE41FjIRs8mhcYcybWlfg.jpeg" /><figcaption>Image generated with Microsoft Copilot Designer</figcaption></figure><p>In December 2022 we switched from the traditional <strong>transitive R classes</strong> to the back then relatively new <strong>non-transitive R classes</strong> behavior in our Android app.</p><p>With this change, we hoped to get faster build times. Especially since the <a href="https://developer.android.com/build/optimize-your-build#use-non-transitive-r-classes">official Android documentation</a> says so:</p><blockquote>Use non-transitive <a href="https://developer.android.com/reference/android/R">R classes</a> to have faster builds for apps with multiple modules […] This leads to faster builds and the corresponding benefits of compilation avoidance.</blockquote><p>Since our app currently has 93+ Gradle modules (and growing), we thought this would be a significant benefit for us.</p><p>Unfortunately, after months of using this feature, we realized that this isn’t the case. We found out that when adding or removing a string in a module, all of its dependents are still recompiled. Which in our case is about half of the whole app.</p><p>Didn’t the docs say something about faster builds and compilation avoidance? Let’s find out what they meant by that and why it doesn’t apply to our app.</p><h4>Non-transitive R class explained</h4><p>As an Android developer, you’re probably familiar with the R class. It is a class that contains fields that you can use to reference resources. For example, to get a (translated) string from your resources, you would use in code something like getString(R.string.app_name).</p><p>The R class is generated for you by the build system. Traditionally, each module generates its own R class, which contains its resource identifiers. Not only that, they also contain every identifier of every transitive dependency. This is the reason why, for example, you could say getString(R.string.library_name) while importing your app R class (guru.stefma.app.R) inside your app module, even though the library_name resource is part of a library module used in app as a dependency. In fact, the R class generated by the app module also contains the resource identifiers of the library.</p><p>Exactly this has changed with the use of <strong>non-transitive R classes</strong>. With this feature enabled, each module’s R class contains only the resource identifiers it defines — no more, no less. Therefore, if you want to use a resource from a dependency in your app module, you have to import exactly that R class. That is, you must import guru.stefma.library.R instead of the R from your app (guru.stefma.app.R).</p><p>The following image also illustrates this concept:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*K9RvWhNPQw-8mkj2AOddgQ.png" /></figure><p>This results in significantly smaller R classes in your project overall. At first glance, it also makes sense that this will reduce build time since there is no need to recreate an R class for each dependent module whenever you add or remove a new resource from a module. But is this really the case?</p><h4>Our Android app architecture</h4><p>Before I explain why this doesn’t give us the improvement we were hoping for, I need to explain what our architecture looks like.</p><p>Our architecture is quite flat. We have two top-level buckets, feature and lib, which contain multiple feature and lib modules, respectively. While feature modules shouldn’t reference each other, lib modules are allowed to do so. However, we have a special lib module called strings. For legacy and localization reasons, all of our strings are contained in this module. Every time a feature (or lib, but it is desirable not to use strings in a lib, but unfortunately sometimes it is unavoidable) needs access to our strings, it must include the :lib:strings module as a dependency. This is the case for all of our features.</p><p>So our project structure looks like this:</p><pre><br>lib<br>- strings<br>  [...]<br>feature<br>- feature1 dependsOn :lib:strings<br>- feature2 dependsOn :lib:strings<br>- feature3 dependsOn :lib:strings<br>- [...]</pre><blockquote><strong>Info:</strong> If you want to have a more in-depth look at our architecture, check out the following blog:</blockquote><p><a href="https://stefma.medium.com/a-birds-eye-view-of-the-ioki-android-app-architecture-8b21d721a446">A bird’s eye view of the ioki Android app architecture</a></p><h4>A short explanation of compilation avoidance</h4><p>Compilation avoidance is, as the name suggests, a feature to avoid (re)compiling classes in Gradle modules.</p><p>This feature only makes sense in <a href="https://docs.gradle.org/8.6/userguide/intro_multi_project_builds.html">multi-module Gradle projects</a> and tries to avoid recompiling a dependent module. In our case, the app module shouldn’t be recompiled when we make changes in our library module, as long as those changes don’t affect <a href="https://en.wikipedia.org/wiki/Application_binary_interface">the ABI</a>.</p><p>There is even a detailed <a href="https://blog.gradle.org/compilation-avoidance">blog post</a> from Gradle that explains this concept in detail. But to sum it up how avoiding recompiling a module works, if only private, internal, or function bodies were changed, Gradle does not need to recompile dependent modules. As soon as public classes or function signatures change, compilation avoidance can’t kick in and every dependent of that module has to be recompiled.</p><blockquote><strong>Note:</strong> There is also the concept of <strong>incremental Kotlin/Java avoidance,</strong> which goes a step further and avoids recompiling classes that are not affected by a dependency’s (public) class changes. But that is a bit beyond the scope of this blog. However, if you’re curious, there is <a href="https://blog.gradle.org/our-approach-to-faster-compilation">another blog</a> by Gradle that explains this concept.</blockquote><h4>The problem</h4><p>With all the information provided above, you might already know why <strong>non-transitive R classes</strong> don’t give us any build speed improvements, right? 😉</p><p>At the beginning of the blog, I mentioned that even the Android documentation describes that projects using non-transitive R classes do “<em>benefit from compilation avoidance</em>”. While this is true in general (I’ll explain this later in this blog), it has no impact on our project with this given architecture.</p><p>The reason for this is how compilation avoidance works together with our architecture. Earlier in this blog, I mentioned that once a public class changes, <strong>compilation avoidance will not work</strong>. But, as soon as you add or remove a resource from your module, the <strong>public R class</strong> adds or removes a public field. Therefore, every dependent needs to be recompiled. With our architecture, where all of our features depend on :lib:strings, all of our features must be recompiled whenever we add or remove a string to or from :lib:strings. We don’t have a significant build speed benefit from using non-transitive R classes.</p><h4>An experimental project</h4><p>Are you more of a hands-on kind of guy and want to poke around in the source code and play with an example? I got you covered:</p><p><a href="https://github.com/StefMa/NonTransitiveRClassAndCompilationAvoidance">GitHub - StefMa/NonTransitiveRClassAndCompilationAvoidance: An experimental project that demonstrate that in case a new resource (e.g. a new string in `strings.xml`) were added to a module, all dependent modules has to be recompiled again</a></p><p>If you’re missing something, want to make a comment, or just have general feedback, feel free to open a new issue.</p><h4>The non-transitive R classes benefit</h4><p>In what situations does the non-transitive R class feature have an impact on compilation avoidance? When you have a dependency tree that is at least three levels deep. Suppose you have a module app that depends on lib, while lib depends on common, and you add or remove a resource to or from common. In this case, and given that lib adds common as an implementation dependency and not as an api dependency, compilation avoidance kicks in for app so that app doesn’t need to be recompiled.</p><p>Obviously, the public R class of common has been changed, so lib needs to be recompiled. But since lib hasn’t changed (because the lib R class doesn’t get new fields), app doesn’t need to be recompiled. The app module makes use of compilation avoidance 🎉</p><p>Of course, the same goes for every dependent up the dependency tree. Imagine there are 10 more modules “above” app, they don’t need to be recompiled either. With transitive R classes, on the other hand, they all need to be recompiled because the R class of each module has changed.</p><p>Savvvy?</p><h4>Disclaimer</h4><p>I wrote this blog post simply to show you what I found out. I’m not against this feature, or even saying you shouldn’t enable it. Well, enabling it has a significant effect, because your R classes don’t get blown up with (unnecessary) fields from their transitive dependencies. This alone is a huge benefit. However, in terms of build speed, this change may not have such a big impact on your project, depending on your project structure.</p><p>So if you are still considering whether or not to switch to non-transitive R classes, do it. It will definitely bring benefits. But depending on your project structure, maybe not the ones you expected 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6296922db40f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The most condensed guide to publish to Maven Central with Gradle]]></title>
            <link>https://blog.stackademic.com/the-most-condensed-guide-to-publish-to-maven-central-with-gradle-1b612b1b9c40?source=rss-179e136461f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b612b1b9c40</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[gradle]]></category>
            <dc:creator><![CDATA[Stefan M.]]></dc:creator>
            <pubDate>Wed, 29 Nov 2023 08:29:52 GMT</pubDate>
            <atom:updated>2023-12-09T19:16:58.218Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Most Condensed Guide to Publish to Maven Central with Gradle</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IRUPsPii1imiDZwO" /><figcaption>Image created with Bing Image Creator</figcaption></figure><h4>Accounting</h4><p><em>Create a Jira account</em><br>Head over to <a href="https://issues.sonatype.org/">https://issues.sonatype.org</a> and sign up.</p><p><em>Create a Jira ticket</em><br>Create a ticket on the <a href="https://issues.sonatype.org/projects/OSSRH/">OSSRH project</a>. <a href="https://issues.sonatype.org/browse/OSSRH-96900">Example ticket</a>.</p><p><em>Optional: Create a TXT record for your domain.<br></em>This is only required if you want to publish your artifacts with a <strong>groupId</strong> other than io.github.username, io.gitlab.username, io.gitee.username, io.bitbucket.username, io.sourceforge.username.</p><pre># Check the TXT records for ioki.com<br>dig -t txt ioki.com<br><br># Output<br># ...more<br>;; ANSWER SECTION:<br>ioki.com.  3600 IN TXT &quot;OSSRH-96900&quot;<br># ...more</pre><p><em>Reopen the Jira ticket<br></em>Required to start the automated process of checking the TXT record.</p><h4>Signing</h4><p><em>Create a key pair<br></em>Install <a href="https://gnupg.org/">GPG</a> and create a new key pair</p><pre>gpg --gen-key</pre><p>You will be asked for an E-Mail address and a password.</p><p><em>Optional: Delete the signing subkey<br></em>Some tools will create a <strong>signing subkey</strong>. We have to delete them. Only the main private key should sign the artifacts.</p><pre># This will list all your public keys<br>gpg --list-keys<br><br># Search for the just created public key and edit it<br>gpg --edit-key [KeyId]<br><br># Search for the subkey (if available)<br># that has `usage: S` and select them<br>key [KeyIndex]<br><br># Delete the key<br>delkey<br><br># Save the key deletion<br>save</pre><p>The first two commands are mandatory to find out if there is a signing subkey. If there is none, you don’t need to do the other steps and can just quit the editing.</p><p><em>Optional but recommended: Change the expire date<br></em>It is not required if you want to extend the expiration date every two years — which is the default expiration time.</p><pre># Edit the key again<br>gpg --edit-key [KeyId]<br><br># Go into the expire tooling window<br>expire<br><br># Enter 0 (zero) for &quot;key never expires&quot;<br>0<br><br># Save the new key expire date<br>save</pre><p><em>Publish the key to an keyserver<br></em>As time of writing, <a href="http://keyserver.ubuntu.com/">keyserver.ubuntu.com</a>, <a href="https://pgp.mit.edu/">pgp.mit.edu</a>, and <a href="https://keys.openpgp.org/">keys.openpgp.org</a> are supported.</p><pre># Publish they key to the ubuntu keyserver<br>gpg --keyserver keyserver.ubuntu.com --send-keys [KeyId]</pre><p>The steps above are one-time steps. <br>The steps below are required for each project you want to publish to Maven Central and may vary slightly depending on the type of project you have.</p><h4>Continues Delivery</h4><p><em>Create an ASCII armor formatted private key</em><br>To sign the artifacts later we have to put the private key to our CD server</p><pre># Export the secret key in ASCII armor and save it in key.asc<br>gpg --export-secret-keys --armor [KeyId] &gt; key.asc</pre><p><em>Put the content of the key.asc into your CD as an environment variable<br></em>Give it a proper name so you can recognize it later in your scripts. What about GPG_SIGNING_KEY?</p><p><em>Put the key password into your CD as an environment variable</em><br>What about GPG_SIGNING_PASSWORD?</p><p><em>Put the Jira account name and password into your CD as environment variables<br></em>What about SONATYPE_USER and SONATYPE_PASSWORD?</p><h4>Coding</h4><p><em>Setup publishing to publish sources and javadocs<br></em>It is required to publish Jar files with the -sources and -javadoc classifiers. However, these Jar files can also be empty or just contain your README file.</p><pre>val dokkaJar = tasks.register&lt;Jar&gt;(&quot;dokkaJar&quot;) {<br>  dependsOn(tasks.dokkaHtml)<br>  from(tasks.dokkaHtml.flatMap { it.outputDirectory })<br>  archiveClassifier.set(&quot;javadoc&quot;)<br>}<br><br>publishing {<br>  publications {<br>    publications.withType&lt;MavenPublication&gt; {<br>      artifact(dokkaJar)<br>      // ...more<br>    }<br>  }<br>}<br>   </pre><p>This will put the output of the <a href="https://kotlinlang.org/docs/dokka-get-started.html">dokkaHtml</a> tasks into a Jar file named as something-javadoc.jar and add this file to any publication of the type <a href="https://docs.gradle.org/8.4/dsl/org.gradle.api.publish.maven.MavenPublication.html">MavenPublication</a>. <a href="https://github.com/ioki-mobility/kmp-lokalise-api/pull/34">Example pull request</a>.</p><blockquote><strong>Note: </strong><a href="https://kotlinlang.org/docs/multiplatform-publish-lib.html#disable-sources-publication">Kotlin Multiplatform</a> will automatically add the sources Jar to the publication. This may not be the case for pure Kotlin, Java, or Android projects. You will need to set up a task similar to your build script and add it to the publication.</blockquote><p><em>Format the POM file according to the requirements<br></em>You have to provide at least name, description, url, licenses.license.name, licenses.license.url, developers.developer.name, developers.developer.email, scm.url, scm.connection, scm.developerConnection in the POM file. <a href="https://github.com/ioki-mobility/kmp-lokalise-api/pull/36">Example pull request</a>.</p><p><em>Add the sonatype repositories to publishing<br></em>There are two different repositories to push to. One is for -SNAPSHOT releases, and the other one is a staging repository where you have to push real releases and later <strong>promote</strong> (<strong>close</strong> and <strong>release</strong>) them to the release repository that is automatically synchronized with Maven Central.</p><pre>publishing {<br>  // ...more<br>  repositories {<br>    maven(&quot;https://s01.oss.sonatype.org/content/repositories/snapshots/&quot;) {<br>      name = &quot;SonatypeSnapshot&quot;<br>      credentials {<br>        username = System.getenv(&quot;SONATYPE_USER&quot;)<br>        password = System.getenv(&quot;SONATYPE_PASSWORD&quot;)<br>      }<br>    }<br>    maven(&quot;https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/&quot;) {<br>      name = &quot;SonatypeStaging&quot;<br>      credentials {<br>        username = System.getenv(&quot;SONATYPE_USER&quot;)<br>        password = System.getenv(&quot;SONATYPE_PASSWORD&quot;)<br>      }<br>    }<br>  }<br>}</pre><p><a href="https://github.com/ioki-mobility/kmp-lokalise-api/pull/38">Example pull request</a>.</p><p><em>Publish to the staging repository<br></em>At this point you should be able to publish your project to both the snapshot and staging repositories. <a href="https://github.com/ioki-mobility/kmp-lokalise-api/blob/d0d991a3ac58056e4f5c3e3223b1c4073e3d1ed6/.github/workflows/publish-snapshots.yml">Example GitHub Action.</a></p><pre># Publish all publications to the snapshot repository<br>./gradlew publishAllPublicationsToSonatypeSnapshotRepository<br><br># Publish all publications to the staging repository<br>./gradlew publishAllPublicationsToSonatypeStagingRepository</pre><p><em>Promote (close and release) to the release repository<br></em>This can be done either manually or via HTTP API calls</p><p><em>Manually promote (close and release)<br></em>Go to <a href="https://s01.oss.sonatype.org/#welcome">https://s01.oss.sonatype.org/</a> and log using your Jira credentials. Click on <strong>Staging Repositories</strong>, locate your deployment and click on <strong>Close</strong>. After the staging release closes, you can click on <strong>Release</strong>. This starts the process of synchronizing to the project with Maven Central.<br>You can then safely <strong>Drop</strong> the staging repository.</p><p><em>Automatic promote (close and release) with HTTP API calls<br></em>First, you need to find out the staging profile id and the staging repositoy id</p><pre># Replace userName and password with your Jira credentials<br>curl --user userName:password https://s01.oss.sonatype.org/service/local/staging/profile_repositories</pre><p>This will return something like</p><pre>&lt;stagingRepositories&gt;<br>  &lt;data&gt;<br>    &lt;stagingProfileRepository&gt;<br>      &lt;profileId&gt;5f2071504368e&lt;/profileId&gt;<br>      &lt;profileName&gt;com.ioki&lt;/profileName&gt;<br>      &lt;profileType&gt;repository&lt;/profileType&gt;<br>      &lt;repositoryId&gt;comioki-1000&lt;/repositoryId&gt;<br>      &lt;!-- More --&gt;<br>    &lt;/stagingProfileRepository&gt;<br>  &lt;/data&gt;<br>&lt;/stagingRepositories&gt;</pre><p>Use the profileId and repositoryId properties to <strong>Close</strong> the repository</p><pre># Replace userName and password with your Jira credentials<br># as well as the profileId (here 5f2071504368e)<br># and the repositoryId (here comioki-1000)<br>curl -X POST -H &#39;Content-Type: application/json&#39; --user userName:password https://s01.oss.sonatype.org/service/local/staging/profiles/5f2071504368e/finish -d &#39;{&quot;data&quot;: {&quot;stagedRepositoryId&quot;:&quot;comioki-1000&quot;,&quot;targetRepositoryId&quot;:&quot;release&quot;}}&#39;</pre><p>You can then <strong>Release</strong> the content of the staging repository to the release repository which automatically synchronizes them with Maven Central</p><pre># Replace userName and password with your Jira credentials<br># as well as the profileId (here 5f2071504368e)<br># and the repositoryId (here comioki-1000)<br>curl -X POST -H &#39;Content-Type: application/json&#39; --user userName:password https://s01.oss.sonatype.org/service/local/staging/profiles/5f2071504368e/promote -d &#39;{&quot;data&quot;: {&quot;stagedRepositoryId&quot;:&quot;comioki-1000&quot;,&quot;targetRepositoryId&quot;:&quot;release&quot;}}&#39;</pre><p>Finally, you can safely <strong>Drop</strong> the staging repo</p><pre># Replace userName and password with your Jira credentials<br># as well as the profileId (here 5f2071504368e)<br># and the repositoryId (here comioki-1000)<br>curl -X POST -H &#39;Content-Type: application/json&#39; --user userName:password https://s01.oss.sonatype.org/service/local/staging/profiles/5f2071504368e/drop -d &#39;{&quot;data&quot;: {&quot;stagedRepositoryId&quot;:&quot;comioki-1000&quot;}}&#39;</pre><p>Resources I found (useful) in my research and implementation:</p><ul><li><a href="https://central.sonatype.org/">Offical Central Repository documentation</a></li><li><a href="https://central.sonatype.org/publish/publish-guide/#create-a-ticket-with-sonatype">Offical Central Repository documentation — Jira account</a></li><li><a href="https://central.sonatype.org/publish/requirements/#a-complete-example-pom">Offical Central Repository documentation — POM file</a></li><li><a href="https://central.sonatype.org/publish/requirements/gpg/">Offical Central Repository documentation — GPG</a></li><li><a href="https://central.sonatype.org/publish/requirements/coordinates/">Offical Central Repository documentation — GroupId/Coordinates</a></li><li><a href="https://central.sonatype.org/publish/release/">Offical Central Repository documentation — Releasing</a></li><li><a href="https://oss.sonatype.org/nexus-staging-plugin/default/docs/index.html">Nexus Staging Plugin REST API documentation</a></li><li><a href="https://github.com/vanniktech/gradle-maven-publish-plugin">Some implementation details of the </a><a href="https://github.com/vanniktech/gradle-maven-publish-plugin">vanniktech/radle-maven-publish-plugin</a></li><li><a href="https://github.com/gradle-nexus/publish-plugin">Some implementation details of the </a><a href="https://github.com/gradle-nexus/publish-plugin">gradle-nexus/publish-plugin</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-use-gpg-to-encrypt-and-sign-messages">Tutorial of how to sign messages by DigitalOcean</a></li><li><a href="https://docs.gradle.org/8.4/userguide/signing_plugin.html">Gradle documentation — The Signing Plugin</a></li><li><a href="https://docs.gradle.org/8.4/userguide/publishing_maven.html">Gradle documentation —Maven Publish Plugin</a></li></ul><h3>Stackademic</h3><p><em>Thank you for reading until the end. Before you go:</em></p><ul><li><em>Please consider </em><strong><em>clapping</em></strong><em> and </em><strong><em>following</em></strong><em> the writer! 👏</em></li><li><em>Follow us on </em><a href="https://twitter.com/stackademichq"><strong><em>Twitter(X)</em></strong></a><em>, </em><a href="https://www.linkedin.com/company/stackademic"><strong><em>LinkedIn</em></strong></a><em>, and </em><a href="https://www.youtube.com/c/stackademic"><strong><em>YouTube</em></strong></a><strong><em>.</em></strong></li><li><em>Visit </em><a href="http://stackademic.com/"><strong><em>Stackademic.com</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b612b1b9c40" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/the-most-condensed-guide-to-publish-to-maven-central-with-gradle-1b612b1b9c40">The most condensed guide to publish to Maven Central with Gradle</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>