— Kotlin, Android, Jackson, InvalidDefinitionException — 1 min read
In my recent project updates, which included a bump to Kotlin 1.8.10, I faced an unexpected obstacle. The release version of my APK persistently crashed, showing an error message labeled InvalidDefinitionException
. This article delves into the problem's origins, identifies the cause within the Jackson library, and offers solutions.
While upgrading my project and upgrading to Kotlin 1.8.10, I encountered an issue when testing my the release build. This issue manifested as an InvalidDefinitionException
- error related to the Jackson library, specifically jackson-module-kotlin
.
Upon investigation, it became evident that the issue primarily resided within the Jackson library, more precisely, the jackson-module-kotlin
. Or more accurately - this problem seemed to stem from compatibility challenges with Kotlin 1.8.10 and R8.
To address this issue temporarily, I downgraded Kotlin to version 1.7.0. This action successfully resolved the InvalidDefinitionException
problem and restored the functionality of the application. It's worth noting that this solution may not be applicable to those who were using Kotlin versions lower than 1.6.0 before the upgrade - because I was already using AGP 7.1.0.
For users encountering the InvalidDefinitionException
issue with Kotlin versions below 1.6.0, an alternative solution involves updating the Android Gradle Plugin (AGP) to version 7.1.0 or newer. This adjustment addresses compatibility issues between R8 and Jackson. Additional information on this matter is available on the Google Issue Tracker.
Unfortunately, a comprehensive solution for using Kotlin 1.8.10 alongside Jackson remains elusive... While the issue tends to disappear when using Kotlin versions 1.6.0 to 1.7.0, it resurfaces when upgrading to Kotlin versions 1.8.0 or higher. I'm going to keep on the look out for a solution because eventually I'm going to have to use 1.8.10+ in my projects.