Skip to content

Android build fails: kotlin-stdlib 2.2.x on classpath but plugin compiled with Kotlin 1.9.25 #18

Description

@ongkristopher

Description

@onesignal/capacitor-plugin@1.0.2 fails to build on Android in a Capacitor 8 project. Root cause is a Kotlin stdlib version mismatch: the plugin's catalog pins Kotlin to 1.9.25, but Gradle's version conflict resolution forces kotlin-stdlib:2.2.20 onto the compile classpath (strict constraint from elsewhere). The 1.9.25 compiler cannot read 2.2.0 metadata, so mutableMapOf, mutableSetOf, and friends become unresolved — which then cascades into "Cannot infer a type" errors for every lambda parameter using those builders.

Environment

Tool Version
@onesignal/capacitor-plugin 1.0.2
@capacitor/core / cli / android 8.2.0
Android Gradle Plugin 8.13.0
Gradle 8.14.3
Kotlin (embedded in Gradle) 2.0.21
Kotlin (plugin's catalog libs.versions.toml) 1.9.25
Kotlin stdlib on classpath (after resolution) 2.2.20 (strictly)
compileSdk / targetSdk / minSdk 36 / 36 / 24
JDK OpenJDK 21.0.9
pnpm 10.30.3
Node 24.14.0

Steps to reproduce

  1. Capacitor 8.2.0 project with Android platform.
  2. pnpm add @onesignal/capacitor-plugin@1.0.2
  3. pnpm exec cap sync android
  4. cd android && ./gradlew :app:assembleDebug

Actual behavior

> Task :onesignal-capacitor-plugin:compileDebugKotlin FAILED
e: Incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
e: ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.20/.../kotlin-stdlib-2.2.20.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module
    Module was compiled with an incompatible version of Kotlin.
    The binary version of its metadata is 2.2.0, expected version is 1.9.0.
e: ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.20/.../kotlin-stdlib-2.2.20.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module
    Module was compiled with an incompatible version of Kotlin.
    The binary version of its metadata is 2.2.0, expected version is 1.9.0.
e: ~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.2.20/.../kotlin-stdlib-2.2.20.jar!/META-INF/kotlin-stdlib.kotlin_module
    Module was compiled with an incompatible version of Kotlin.
    The binary version of its metadata is 2.2.0, expected version is 1.9.0.
e: <PROJECT>/node_modules/@onesignal/capacitor-plugin/android/src/main/kotlin/com/onesignal/capacitor/OneSignalCapacitorPlugin.kt:51:48 Unresolved reference: mutableMapOf
e: <PROJECT>/node_modules/@onesignal/capacitor-plugin/android/src/main/kotlin/com/onesignal/capacitor/OneSignalCapacitorPlugin.kt:52:39 Unresolved reference: mutableSetOf
e: OneSignalCapacitorPlugin.kt:246:37 Cannot infer a type for this parameter. Please specify it explicitly.
e: OneSignalCapacitorPlugin.kt:316:34 Cannot infer a type for this parameter. Please specify it explicitly.
e: OneSignalCapacitorPlugin.kt:375:37 Cannot infer a type for this parameter. Please specify it explicitly.
e: OneSignalCapacitorPlugin.kt:577:38 Cannot infer a type for this parameter. Please specify it explicitly.

FAILURE: Build failed with an exception.
Execution failed for task ':onesignal-capacitor-plugin:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error.

Dependency tree excerpt

./gradlew :onesignal-capacitor-plugin:dependencies --configuration debugCompileClasspath:

\--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:{strictly 1.8.22} -> 1.8.22 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:{strictly 1.8.22} -> 1.8.22 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib:{strictly 2.2.20} -> 2.2.20 (c)
+--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 -> 2.2.20
+--- project :capacitor-android
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0 -> 1.8.22 (c)
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.25 -> 2.2.20 (*)

The plugin asks for kotlin-stdlib:1.9.25, but a {strictly 2.2.20} constraint elsewhere on the classpath overrides it. Result: 1.9.25 compiler ↔ 2.2.20 stdlib bytecode → metadata version mismatch.

Expected behavior

Plugin compiles cleanly against a default Capacitor 8 + AGP 8.x project, regardless of what Kotlin version the parent project's classpath ends up resolving to.

Workarounds attempted

  1. Set kotlin_version = '2.0.21' in android/variables.gradle so the plugin's propertyOrCatalog("kotlin_version", "kotlin") lookup reads that instead of the catalog default.
    • Result: build progresses further but fails with Internal compiler error in the same task.
  2. Rolling back to onesignal-cordova-plugin@5.3.8: builds and runs cleanly.

Suggested fixes

A few options the maintainers could consider:

  1. Match the Kotlin version Capacitor 8 ships with by default. Capacitor 8's bundled Gradle uses Kotlin 2.0.21; pinning the plugin's catalog kotlin = "2.0.21" (or unsetting it entirely so it inherits from the parent project) would avoid the conflict in the common case.
  2. Add a Gradle dependency resolution rule in the plugin's build.gradle.kts to force a specific kotlin-stdlib version compatible with the plugin's compiler, or use kotlinOptions.languageVersion = "1.9" / apiVersion = "1.9" so the 1.9 compiler is happy reading newer stdlib metadata.
  3. Document a required kotlin_version override in the README so consumers know to set ext.kotlin_version in their root project.

Notes

The plugin is new (first published 2026-05-05, currently 1.0.2 as of report) with no related open issues, so this may be the first real-world report on a clean Capacitor 8 project.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions