I'm updating my multi-module multiplatform (androi...
# multiplatform
r
I'm updating my multi-module multiplatform (android/ios/jvm) project from Kotlin 1.7.22 / Gradle 7.5.1 to Kotlin 1.8.10 / Gradle 8.0 and have this issue:
Copy code
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
Anyone encountered this? It's a lint task so it still builds, but it looks weird. (see logs in thread)
Copy code
> Task :modules:files:lintAnalyzeDebug
e: /Users/ribesg/Projects/kommon/modules/date/build/.transforms/08dc39c7d0e8d2d4d8c22c2254b1913c/transformed/out/jars/classes.jar!/META-INF/date_debug.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/ribesg/Projects/kommon/modules/logging/log/build/.transforms/cc069f0764751b886663312279ea1e3b/transformed/out/jars/classes.jar!/META-INF/log_debug.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/ribesg/Projects/kommon/modules/parcel/build/.transforms/6655e5cdb87c32025ff3a339cf946e14/transformed/out/jars/classes.jar!/META-INF/parcel_debug.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/ribesg/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.10/6d5560a229477df9406943d5feda5618e98eb64c/kotlin-stdlib-1.8.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.8.0, expected version is 1.6.0.
e: /Users/ribesg/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.10/6d5560a229477df9406943d5feda5618e98eb64c/kotlin-stdlib-1.8.10.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/ribesg/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.8.10/6d5560a229477df9406943d5feda5618e98eb64c/kotlin-stdlib-1.8.10.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/ribesg/Projects/kommon/modules/files/build/.transforms/8b50949d0fc02d8778ae67ffa6d0c0f3/transformed/out/jars/classes.jar!/META-INF/files_debug.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
e: /Users/ribesg/Projects/kommon/modules/files/build/tmp/kotlin-classes/debug/META-INF/files_debug.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
m
Copy code
expected version is 1.6.0
That's surprising. I would usually link to Gradle compiling with an older version of Kotlin but Gradle 8 should use Kotlin 1.8.10
r
Yes. I'm also using a version catalog with the kotlin version set to 1.8.10, used everywhere. To find outdated mentions of 1.7.22, why not, but 1.6.0?
m
Could it be that
lintAnalyzeDebug
is calling the Kotlin compiler under the hood?
Does it show anything if you run with
-i
?
r
No, nothing more. Just a bunch of
Transforming X
lines. And this, then the errors I shared above and Build Success.
Copy code
Caching disabled for task ':modules:files:lintAnalyzeDebug' because:
  Build cache is disabled
Task ':modules:files:lintAnalyzeDebug' is not up-to-date because:
  Task.upToDateWhen is false.
Android Lint: Reusing lint classloader 30.3.0
Android Lint: Disposing Uast application environment in lint classloader [30.3.0]
I tried cleaning a bunch of gradle caches with no luck
Adding this to my root
build.gradle.kts
file "fixes" it:
Copy code
buildscript {
    dependencies.classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
}
But I shouldn't need that… Right? It actually doesn't fix anything, I just thought because it didn't show errors when running the task again without clean (which didn't actually run the task I guess)
m
weird. where did you declare the KGP version else?
I mean it's either in
buildSrc
(or
build-logic
) dependencies or in your root
build.gradle.Kts
Copy code
plugins {
  id("org.jetbrains.kotlin.android").version("1.8.10")
}
Or is it somewhere else?
r
In `buildSrc`'s
build.gradle.kts
I have this
Copy code
dependencies {
    compileOnly(gradleKotlinDsl())
    implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
    implementation(libs.gradle.android)
    implementation(libs.gradle.kotlin)
}
Which references my version catalog
libs.versions.toml
which contains this
Copy code
[versions]
…
android-gradle = "7.3.0"
gradle = "8.0"
kotlin = "1.8.10"
…
[libraries]
…
gradle-android = { module = "com.android.tools.build:gradle", version.ref = "android-gradle" }
gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
…
m
Interesting... Maybe it's
gradleKotlinDsl()
doing funky stuff?
r
Removed it, no change. Seems like this dependency wasn't even needed anymore
I was wrong, the dependency in the buildscript doesn't fix anything, I probably mistakenly ran the task without
--rerun
or
clean
and understood the lack of error logs as success
a
have you added the Kotlin BOM?
Copy code
implementation(platform(kotlin("bom")))
r
Never heard of it, at which level would I put that?
a
anywhere that the Kotlin plugin is applied
Copy code
plugins {
  kotlin("jvm")
}

dependencies {
  implementation(platform(kotlin("bom")))
}
Note that different Configurations (
implementation
,
testFixturesImplementation
,
androidInstrumentedTest
) might need to re-apply it.
you can also apply it without the
kotlin()
helper function (which automatically adds the Kotlin version)
Copy code
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))
m
how would that solve anything?
a
my guess is that there’s a transitive dependency on an older Kotlin dependency being brought in by a plugin or another dependency, so the BOM would align it
m
I'm really curious if it works. I always thought
expected version is 1.6.0
was coming from the compiler
mmmm unless it's
kotlinx.metadata
🤔
which lint could maybe depend on...
a
I made a mistake @ribesg - make sure to wrap it with
platform()
. I’ve updated my examples above.
m
"expected version is" comes from kotlinx.metadata. So maybe it's using the 1.8.x compiler with an outdated
kotlinx.metadata
version
Which is still weird, I'd expect the compiler to depend on the same version of metadata
r
I don't see any change after adding that dependency in a lot of places. There are hundreds of places I defines dependencies… I tried to add it for every platform the module I'm testing with compiles to and all the modules listed in the logs, no change
a
try running
Copy code
./gradlew  :modules:files:dependencies
and looking for any kotlin/kotlinx dependencies that aren’t 1.8.10
r
I have a lot of dependencies referencing Kotlin 1.7 but not 1.6
Every reference ends with the form
1.7.20 -> 1.8.10
which means it's actually replaced with the updated version iirc
d
@ribesg did you figure out what the issue was? I'm getting a similar error
r
No. I'm just riding the warnings wave.
k
Having the same error running tests on a lint module we have FWIW.
Copy code
kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
and the jdk7/jdk8 versions of it show in the warnings too. They're all in the gradle cache for paths. I'm also not in a multiplatform project.
a
Has anyone in this thread been able to fix the problem? I am running into a similar issue with the lint task failing on my Android project when trying to update from Kotlin 1.7.10 to 1.8.20
Copy code
e: /root/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-parcelize-runtime/1.8.10/b0e9f707501a1d64e47aee02bfd7d963b8448fba/kotlin-parcelize-runtime-1.8.10.jar!/META-INF/parcelize-runtime.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
d
./gradlew --version
what's your Kotlin version there?
a
Hmm, that shows 1.5.31
d
I think you should upgrade that
a
Thank you for that! Is there a way to upgrade only the Kotlin version of the gradle wrapper? Or should I upgrade the gradle wrapper to achieve this?
d
I'm not an expert at this, but I think upgrading the wrapper is probably the way to go
a
Got it, thank you!
j
I'm getting multiple of these errors, for both the project/build directory and gradle cache:
Copy code
~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.9.0/8ee15ef0c67dc83d874f412d84378d7f0eb50b63/kotlin-stdlib-1.9.0.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
m
Can you share a build scan/full stacktrace?
Also double check your Gradle version
Ah never mind, it's lint so it still builds, right? So no stacktrace? build scan would be interesting though
j
I'm using Gradle 8.2.1 and AGP 8.0.2, which I just updated from 7.4.2 (with IntelliJ support in 2023.2). I use a version catalog for all versions in buildSrc and all modules.
👍 1
I'll confirm what AGP 7.4.2 does, if it's different.
And yes, this doesn't affecting actually assembling the library or running tests, which works just fine. It's just the
build
task which calls this AGP
lint
task that fails.
👍 1
m
Looks like it is this bug
The issue says it's fixed with AGP 8.2.0-alpha12 or just
android.experimental.lint.version=8.1.0-rc01
j
Ah, yes. Exactly the issue. So weird the linter is requiring its own internal Kotlin version.
nod 1
m
Quizz: how many Kotlin versions are involved in your typical Android build? 😄 The answer might surprise you
😄 3
(I don't have the answer)
j
With the fix coming in AGP 8.2, we should expect it sometime in the next one or two years I guess. 😞 Hopefully IntelliJ doesn't mind using the newer lint version at least.
🤞 1
Confirmed AGP 7.4.2
./gradlew lint
has this same error. But
android.experimental.lint.version=8.1.0-rc01
works with AGP 8.0.2, and with IntelliJ IDEA 2023.2. 😅
🙏 1
Thank you for your help, @mbonnin.
💙 1
4982 Views