A Day of Resolving Errors in Android Jetpack Compose
A couple of days ago I wanted to add a new dependency, the AWS SDK, to my Jetpack Compose app while suddenly everything came to a full stop.
What looked like an easy to fix error message turned out in a chain of error messages that had to be solved one by one. It literally felt I have opened Pandoras box and was struggling to close it again.
Kotlin Update #
Let’s start with the first error message right after adding the dependency and trying to compile again.
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
This error occurs when the version of Kotlin used to compile the module is different from the version of Kotlin specified in the build.gradle
file of your project.
To fix this, you can update the version of Kotlin specified in the build.gradle
file to match the version that was used to compile the module.
In the project build.gradle
I have changed
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21”
to
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10”
However, that was an older project that I have created a year ago.
When I create a new project as of today, the structure of the build.gradle
is different
buildscript {
...
}
plugins {
...
id 'org.jetbrains.kotlin.android' version '1.5.21' apply false
}
...
Here, I would have to make the following change.
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
One down. On to the next.
Gradle Update #
In the hope that everything is fine again I have tried to compile but got this message.
Minimum supported Gradle version is 7.5. Current version is 7.2.
That’s a clear one, or so it seemed … Surfing Stack Overflow provided me with numerous fixes and I wasn’t sure. So I have tried the simplest one that was marked as solution: invalidating the caches.
After Android Studio came up I have tried to build again and got a different error message.
Android Studio Update #
The problem seemed to be a bit bigger. While coding along all those months, I was really neglecting my development environment. The result was this error message while trying to compile:
This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 2021.2.1 or newer.
Yes, my version of Android Studio seemed a bit out-of-date.
After checking for updates and installing the latest version I got a version that was only released a couple of days ago. Couldn’t get any newer than this.
The dialog for clearing the caches also got a few more options.
You might have guessed, it was not the end. The story goes on.
Upgrading the Build Files #
The next error revealed itself as
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
Unfortunately, there wasn’t any other error message that could point me into the right direction.
Therefore I have changed the structure of the build.gradle
with the structure that is equal to new Jetpack Compose projects in the hope this would change something. It was just a gut feeling but it proofed right.
That does not mean I was finished. That would have been too easy.
The next hoop I had to jump through:
Plugin [id: 'com.android.application', version: '7.4.0', apply: false] was not found in any of the following sources:
I was able to resolve this one by adding the following block to the settings.gradle
:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
Changing Dependency Versions #
Apparently I have missed a few things while refactoring the build.gradle
-files.
The next error was stating I was missing my dependency for Dagger and Hilt.
Plugin [id: 'dagger.hilt.android.plugin'] was not found in any of the following sources:
Easy fix. In the module build.gradle
I have added the corresponding dependency.
plugins {
...
id 'com.google.dagger.hilt.android' version '2.44.2' apply false
}
Now the Jetpack Compose version seemed to be off.
e: This version (1.0.1) of the Compose Compiler requires Kotlin version 1.5.21 but you appear to be using Kotlin version 1.7.10 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
I have checked the “Compose to Kotlin Compatibility Map” and decided make the following change in the module build.gradle
from
kotlinCompilerExtensionVersion = "1.0.1"
to
kotlinCompilerExtensionVersion = "1.4.0"
The next error popped up indicating another dependency issue:
The compiler option dagger.hilt.android.internal.projectType is not a recognized Hilt option. Is there a typo?
I had to increase the version number of all my dagger-hilt dependencies to the latest version of “2.44.2” in the app build.gradle
.
While re-adding the Dagger-Hilt plug-in after restructuring the build-files, I have already used the latest version. That’s the reason for the mismatch.
On to the next error …
Hey! Wait a second! I was able to compile again.
The deployment to the simulator worked, the app came up and …
Boom!
My hopes got shattered with a runtime exception:
java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`
This originated from the class that contains all the navigation-related code of my application and a bit of SO-surfing validated my assumption.
So I have updated another dependency in my project build.gradle
, this time the one for the navigation.
implementation 'androidx.navigation:navigation-compose:2.5.1'
Compile! Deploy! RUN!
It worked again!
What a “journey”. It cost me a lot of time to be able to compile my app again. I really wonder how I could have saved myself from all this and prevented it from the beginning.
How do you keep your projects up-to-date? Do you actively check for new dependency versions or do you hope that with new or updated dependencies the whole project does not burst into flames?
Usually I only have to increase a dependency version here or there, but this time was different and quite a “learning experience”.
Feel free to answer in the comments. Any hints are highly appreciated.
Thank you for reading!
- If you enjoyed this, please follow me on Medium
- Buy me a coffee or send me a tip
- Support me and other Medium writers by signing up here
https://twissmueller.medium.com/membership