The Syntax Chronicles: using kapt successfully in Android Studio Jellyfish

When Kotlin kills the Jellyfish groove and how to work around it

Crafted Codes
Women in Technology
7 min readMay 19, 2024

--

MidJourney generated image — Dieser Artikel ist auch auf Deutsch erhältlich

First of all, I would like to say that I realise that Jetpack Compose is the future of Android development, but there are always cases where you still have to work with good old XML. Like in this one. And for those who still have to and are confronted with the kapt error, this article is for them.

Prologue

I have big things coming up at the moment. Big things for me. In just a few months, I’ll be taking a test of the skills I’ve acquired in my training over the past year, but in just a few weeks, I’ll also be taking my first important technical test for a job that I really want. A job at a company that I have been quietly and secretly eyeing for a few years now, like my dog eyeing a treat, and now the day had come: The company advertised a position that I could actually apply for! An Android developer position.

My reaction to this opportunity (literally).

I applied, got through the first interview successfully and was invited to a technical interview (and that without a bachelor’s degree in computer science! It’s like finding a unicorn!). And imposter syndrome and exam anxiety struck.

I’m good in stressful situations. Everyone around me can confirm that. The world is coming to an end? You call me. Like Wonder Woman, I save the day. But an exam? Even two tests?! That’s my kryptonite. So what to do about my exam anxiety? Well, for me, the solution is obvious: I develop an Android app. 💁‍♀️✨ Nothing calms me down more than checking whether I can actively apply my knowledge and then explain it to others (hence this blog). Even if I might still start to stammer in real life. Then I’ll be a stuttering superhero, but I won’t run away from the fight. 🦸‍♀️

The project

Since I always like to kill several birds with one stone and understood that the company also works with XML, I decided to make a “simple” Kotlin and XML Android project. A simple to-do app. Yes… Simple, until I’ve planned everything I found exciting and a few things I’ve never done before. And I want to pour that into an app in less than 2 weeks without being so exhausted during the technical interview that I fall off my chair and babble nonsense. According to ChatGPT, I can expect 3–4 weeks or more. But hey: things are only impossible until you’ve tried them. Right?

Probably my future self, thinking about hammering some sense into me.

Android Studio is definitely of a different opinion

Due to my continuing education and other challenges, it’s been a while since I’ve really used Android Studio. It ran flawlessly on my old projects, but when I tried to start a new project, it kept crashing. So I checked it for updates (none found) and finally I couldn’t avoid uninstalling it completely (which is a lot more work on the Mac than some people realise — if you’re interested I’ll write another tutorial — please post in the comments) and downloading Android Studio Jellyfish. Done and landed in the problem.

The problem

The reason for my suffering.

For my project I need DataBinding and for DataBinding I need kapt (and no, I didn’t just want to use Java code for it — I wanted to stay consistently in Kotlin). So far so simple. But on the one hand I was surprised by the new version catalogue (actually quite cool) and on the other hand I couldn’t implement kapt come hell or high water. No matter what I did. I spent an estimated 3–4 hours doing everything I knew.

Great tutorial by Philipp Lackner on the version catalogue.

I changed the versions, deleted the cache, did a project clean, tried different ways of writing and much more, consulted StackOverflow, GitHub and YouTube, maltreated ChatGPT, wrote a desperate message to my former lecturer, complained to a native app developer friend in a voice message and then went to bed for almost 4 hours. Even in my sleep, I worked through everything I could think of in my dreams until I decided to try the one thing I hadn’t done yet and woke up.

The solution

The problem with kapt is already known to JetBrains, but I haven’t found anywhere in Android Studio where I can set their solution — to use a different Kotlin version. That’s why I chose a new way.

The corresponding section in “Known issues with Android Studio and Android Gradle Plugin”

Find the groove

  1. First of all, I created a new project. For an XML-based Android app, of course, one without an activity.
Select “No Activity” for a new project.

2. Instead of “Kotlin DSL (build.gradle.kts)”, I selected “Groovy DSL (build.gradle)” as the build configuration language, although Kotlin is actually recommended.

Select “Groovy DSL (build.gradle)”.

3. Implementing kapt.

Implementation code for kapt.

4. Finished

My feelings when the solution worked.

Long way, simple solution

You might be wondering why I didn’t come straight out with the solution, but instead told you such a long story about a quick solution. Well, there are several reasons for this.

  1. Just the solution would have been boring — I’m serious. Ultimately, you always have the option to scroll forward to the solution, but for me as the author of this article, it would have been just too boring if I had only typed down the solution. Any AI could have done that.
  2. Even a seemingly simple solution can take a long time — this is something that many people forget. I do too. But it’s especially important for beginner programmers and product and project managers to keep this in mind when they wonder why it sometimes takes so long to fix a bug. Especially when the solution seems so simple. It takes time, because you have to find the solution first and it can take a long time to get there. Whereby “long” is relative. I’ve sat on a bug for weeks and then found the solution, which was actually so simple. If you knew it. But what do I always like to say:

I don’t know what I don’t know and even if I am firmly convinced that I know something, it may be that I don’t know everything, something has changed or I have misunderstood it.

It happens often enough to all of us and really shouldn’t be underestimated. However, it is not necessarily a reason to throw in the towel straight away.

3. You have to celebrate yourself — Yes, this is apparently a small thing, but this small thing could have made the next few months hell for me. I solved the problem on my own. Every experienced developer knows that this is not a matter of course. And anyway, I’m like Farin Urlaub:

“Find yourself good
Just think you’re great
When no one else does
Find yourself good
Give yourself a pat on the back
Give yourself courage”
- Farin Urlaub Racing Team “Find dich gut” from the album “Faszination Weltraum” (2014)

So, even if you “only found the missing semicolon” after what felt like an eternity:

Celebrate yourself! Have a party! You’ve made it!

“Find dich gut” by Farin Urlaub Racing Team

I hope this article helps you both with the kapt bug, but maybe also with not being too hard on yourself when you get stuck again. Sometimes a little sleep or a rubber duck can help (if you don’t understand this hint, feel free to search my other Syntax Chronicles articles — the rubber duck article might help you).

Even an AI couldn’t help here, only my flexible, human mind, which subconsciously presented me with the solution. This supports all the more my conviction that development is a process that is very much influenced by the psyche and that we still have an advantage over AIs here, at least for the time being.

You can find the other articles in the Syntax Chronicles series here:

The Syntax Chronicles 🇬🇧

38 stories

If you liked this article, don’t hesitate to applaud and share it. If you would like to share your own experiences with me, I look forward to your comments and if you don’t want to miss my other articles, feel free to follow me.

This article was translated by using DeepL to save time.

--

--