Search code examples
androidkotlincordovameteor

Kotlin version mismatch in meteor cordova project without any changes


I have a Meteor 2.9.0 (cordova-android 10) project that was working all fine and I could build it on my Windows 10 machine successfully last week. Nothing changed since then from my side yet it now fails and I'm running out of ideas how to fix it.

I'm getting errors about modules being compiled with an incompatible version of Kotlin. Mainly from the PushPlugin, but that's a plugin that I have hardcoded to a specific git commit so it's impossible that anything changed there. Errors:

> Task :app:compileDebugKotlin FAILED
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/Meteor/.gradle/caches/transforms-3/cc5cc74c45c7cc5e76733fe8278ba926/transformed/jetified-kotlin-stdlib-jdk7-1.5.20.jar (version 1.5)
    C:/Users/Meteor/.gradle/caches/transforms-3/adaf9cac4b199e0779758b8aae901bb4/transformed/jetified-kotlin-stdlib-1.7.10.jar (version 1.7)
    C:/Users/Meteor/.gradle/caches/transforms-3/eda4e3aecc1ddb0771d71f6ab843e15d/transformed/jetified-kotlin-stdlib-common-1.7.10.jar (version 1.7)
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: C:/Users/Meteor/.gradle/caches/modules-2/files-2.1/androidx.annotation/annotation/1.5.0/857678d6b4ca7b28571ef7935c668bdb57e15027/annotation-1.5.0.jar!/META-INF/annotation.kotlin_module: 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.
e: C:/Users/Meteor/.gradle/caches/transforms-3/adaf9cac4b199e0779758b8aae901bb4/transformed/jetified-kotlin-stdlib-1.7.10.jar!/META-INF/kotlin-stdlib.kotlin_module: 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.
e: C:/Users/Meteor/.gradle/caches/transforms-3/eda4e3aecc1ddb0771d71f6ab843e15d/transformed/jetified-kotlin-stdlib-common-1.7.10.jar!/META-INF/kotlin-stdlib-common.kotlin_module: 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.
e: D:\GIT\meteor-app\.meteor\local\cordova-build\platforms\android\app\src\main\java\com\adobe\phonegap\push\BackgroundActionButtonHandler.kt: (14, 2): Class 'kotlin.Suppress' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
The class is loaded from C:/Users/Meteor/.gradle/caches/transforms-3/adaf9cac4b199e0779758b8aae901bb4/transformed/jetified-kotlin-stdlib-1.7.10.jar!/kotlin/Suppress.class

I have tried updating my gradle version installed on PC (7.3.1) to 7.6.1, clearing the .gradle/caches directory as well as removing the whole .gradle directory. I un-installed all the Android SDK's and re-installed them again in Android Studio. My app targets sdk 31.

I'm running Java JDK 11.0.17, gradle 7.3.1 but I think meteor/cordova uses it's own gradle version since I saw logs containing gradle 7.1.1. I have searched my entire project (cordova build included) for hardcoded kotlin versions, and all I could find is:

android.json: "xml": "<preference name=\"GradlePluginKotlinVersion\" value=\"1.5.20\" />",

cdv-gradle-config.json:
"KOTLIN_VERSION": "1.5.20",

plugins/@havesource/cordova-plugin-push/plugin.xml:
<preference name="GradlePluginKotlinVersion" value="1.5.20" />

So everything matches, yet somehow it complains about kotlin 1.7.1... I'm already tired of this, it's not the first time I'm struggling for hours with random stuff breaking the android build without me touching anything, Android related things magically disappear from the env variables, things stop working... building for iOS is a pleasure compared to this.

I know there is a ton of similar questions, but all of them refer to modifying gradle settings in the project which I cannot do in this case, because it is all done by cordova and it's plugins. And it worked fine until now!


Solution

  • I have found an answer myself. Seems I'm not the only one haunted. Something has auto-magically changed for others too and building stopped working despite no changes being made. See here: https://github.com/havesource/cordova-plugin-push/issues/218

    Adding the cordova preference to use the higher Kotlin version fixed this, but I wonder what happened and who caused this