Debugging an obscure ML kit bug in Kotlin

So, you're a developer, huh? You know your stuff, you're pretty confident in your abilities. But what happens when you're asked to help a Kotlin developer? You've never used the language before, but you're feeling adventurous. You're ready to jump in and help out, no problem.  

Well, that's exactly what happened to me. I was asked to help a Kotlin developer with their app. I had no experience with Kotlin, but I figured, how hard could it be? Famous last words.  

I was already familiar with the app since I designed it with Figma. It is pretty simple: Scan a barcode or QR code, using the ML Kit's barcode scanning API. One of the advantages of using the kit is that it will work on ALL Android devices. It was doing its job, but all of the sudden it stopped working. The console only showed a "failed to load scan" error. Trying to pin point the bug, I was told it happened after switching the gmail account from one to another. That didn't make any sense, since the app doesn't use any Google service to work. We compiled the app in another device, it worked. However, after switching the Gmail account to another one, it stopped working.

Even after restarting the device, removing all traces of the app, it just did not work. Even the ChatGPT didn't have a clue about the situation. Being the good bug hunter that I am, I asked the kotlin developer why he used the ML kit instead of, I dunno using Flutter to create a kick-ass app. 

He stated that "it is compatible with all devices, in fact at compilation it dowload the kit to use the latest version".That's when it hit me. It wasn't Android Studio downloading the kit, it was the Google Play Services app of the phone downloading it. I realized that it could be a cache problem or some obscure bug that was messing up either the version of the ML kit or the app permissions. The fix? Just clear the Google Play Services cache and data. I did that on both devices, and problem solved! No more issues even while switching Google accounts.

Is it bug in the official Google ML Kit barcode scanner library or the Google Play Services? Come on, Google. You're Google. You're supposed to be the gold standard. This shouldn't be happening, and yet, here we are. That's one of the reasons I keep using Flutter to develop Android apps.

No comments

Powered by Blogger.