1

Screenshot of XCode Project and Build Errors

I have composed a multiplatform project with Android and iOS. The Android app runs and installs successfully, but when I run the iOS app from XCode build, it fails with the below error.

🛑 No matching variant of androidx.compose.foundation:foundation:1.7.0 was found. The consumer was configured to find a library for use during 'kotlin-api', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.klib.packaging' with value 'non-packed', attribute 'org.jetbrains.kotlin.native.target' with value 'ios simulator arm64', attribute

I tried to install the required packages on my M3 MacBook.

1
  • androidx.compose.foundation:foundation:1.7.0 is an Android-specific artifact, that doesn't support iOS target. Perhaps, you're looking for compose multiplatform artifact instead? It has a different package name, check out mvnrepository.com/artifact/org.jetbrains.compose.foundation/… How did you create your project? I recommend to try this wizard kmp.jetbrains.com. If that doesn't work for you, please, share your build.gradle file Commented Feb 21 at 12:14

2 Answers 2

0

Please share your build.gradle file if you need more help. I expect this is coming from pre-compile build phase in your xcode project that builds the KMP part of your app via Gradle (which is standard setup in KMP projects).

Google does not publish the compose multiplatform artifacts for non-android platforms. To use Compose Multiplatform, your build.gradle should look something like this: https://github.com/Kotlin/KMP-App-Template/blob/main/composeApp/build.gradle.kts.

In particular, you need to apply these plugins:

plugins {
  alias(libs.plugins.kotlinMultiplatform)
  alias(libs.plugins.androidApplication)
  alias(libs.plugins.composeMultiplatform)
  alias(libs.plugins.composeCompiler)
}

And instead of depending on the androidx artifacts directly, declare your dependencies like so:

commonMain.dependencies {
  implementation(compose.runtime)
  implementation(compose.foundation)
  ...
}

For posterity, the .toml file declares the exact plugin coordinates:

androidApplication = { id = "com.android.application", version.ref = "agp" }
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
Sign up to request clarification or add additional context in comments.

Comments

0

After some digging, this appears to be an issue when using non-KMP dependencies in the commonMain.dependencies block. In my case, I was using koin-androidx-compose-navigation, which is an Android-only dependency. That will produce this (unhelpful) error.

To get rid of it, I removed dependencies one-by-one until I figured out what the root cause was.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.