Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors

Flutter Aug 9, 2023

When developing in Flutter you might encounter this error: "Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors". In this post, we will break down the error and go over the solution to resolve it.

flutter_showcasing_the_incompatible_classes_were_found_in_dependencies_error

Understanding the error

At the bottom of the error stack, there is a helpful "Flutter Fix" message telling us to update our Kotlin Gradle plugin version in the android\build.gradle file. This is the reason behind the error. Our Kotlin Gradle plugin version is outdated. The message also refers us to a link with all the available versions.

flutter_showcasing_the_flutter_fix_message_at_the_end_of_the_error_stack

Resolving the error

If we go to the link from the error message. We will end up on the Kotlin website and get an overview of all the releases.

kotlin_website_list_of_releases

At the time of wring 1.9.0 is the latest version. The error message also specified the file we need to change: codeonwards_demo/android/build.gradle, where codeonwards_demo is the name of the project.

Now, if you take a look inside that file, you will find a section called buildscript. Within this section, there is a parameter called ext.kotlin_version that is currently set to a specific version, in my case 1.7.10.

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

To resolve the error we need to change this parameter to either the latest version or any higher version of your choice.

buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Once we have updated this parameter, and run our project again you will see that the build is successful.

flutter_building_our_project_after_updating_kotlin_gradle_plugin

Conclusion

We have seen that if you go through the error stack carefully you can see that the solution was already mentioned. However, in this post, we went over the exact steps to make sure that you apply the solution in the right way. Now whenever you come across this error again you know how to handle it.

Tags