In Kotlin multiplatform when i try to use compose module interface or class in non-compose module getting this error when i do maven-publish in windows and ios. For example i created a project and added PR with error message https://github.com/yuvaraj119/Expressus-temp/pull/1

  1. In windows when i run the app it works perfectly no crash

  2. but when i do maven-publish it throws error.

  3. unable to publish only the non-compose module which is consuming compose module.

  4. where all other modules which are not consuming compose module gets published.

  5. even the compose module gets published.

  6. In mac maven-publish get failed and non of the module gets published below mac error

Could not resolve all task dependencies for configuration ':shared:iosArm64CompileKlibraries'.
Could not resolve project :shared-ui-compose.
Required by:
project :shared
> No matching variant of project :shared-ui-compose was found. The consumer was configured to find a usage of 'kotlin-api' of a library, preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64' but:
- Variant 'debugApiElements' capability Expressus:shared-ui-compose:unspecified declares an API of a library, preferably optimized for Android:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
- Variant 'debugRuntimeElements' capability Expressus:shared-ui-compose:unspecified declares a runtime of a library, preferably optimized for Android:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
- Variant 'jvmApiElements' capability Expressus:shared-ui-compose:unspecified declares an API of a library, preferably optimized for standard JVMs:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
- Variant 'jvmRuntimeElements' capability Expressus:shared-ui-compose:unspecified declares a runtime of a library, preferably optimized for standard JVMs:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
- Variant 'metadataApiElements' capability Expressus:shared-ui-compose:unspecified declares a library, preferably optimized for non-jvm:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
- Variant 'releaseApiElements' capability Expressus:shared-ui-compose:unspecified declares an API of a library, preferably optimized for Android:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
- Variant 'releaseRuntimeElements' capability Expressus:shared-ui-compose:unspecified declares a runtime of a library, preferably optimized for Android:
- Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
- Other compatible attribute:
- Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')```
2

There are 2 best solutions below

0
On

This is because your shared declares iOS-targets in addition to jvm and android. This is equivalent of saying "I will compile my code to JVM, Android and iOS".

Therefore, all the dependencies you use in :shared:commonMain should also be compatible at least with those targets. However, shared-ui-compose project declares only jvm and android targets, essentially saying "I know how to compile only for JVM and Android, but not for iOS". The mismatch results in failure.

The general rule is that your dependency should support at least as many targets as you declare.

Unfortunately, in your case, you can't just declare iOS targets in shared-ui-compose, as it will start failing with a similar error because Compose doesn't provide support for iOS targets.

You can remove iOS targets in the consumer project (i.e. in shared). Obviously, you will lose the ability to compile to iOS, but frankly, I don't understand why shared had those targets to begin with, as the project overall doesn't support iOS.

P.S. The reason why you see a different behavior on Windows and MacOS is because the compilation of iOS-targets on Windows-hosts is not supported, and all tasks/build actions connected with iOS targets are just disabled in the build.

0
On

It usually depends on the kotlin library version you're using for multiplatform, because the distributor will have built klibs with a different version from the one in your build. I recommend version 1.8 since it has native target fallback and most maven kmm libraries use it or a bit lower