Anyone knows what usually causes this issue? ```No...
# multiplatform
r
Anyone knows what usually causes this issue?
Copy code
No matching variant of <myKmpLib> was found. The consumer was configured to find a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common'
While trying to build a
shared
module of a KMM app having a dependency on a KMP library defined in its
commonMain
sourceSet
l
Can you show us gradle files ?
r
My lib is a KMP project with targets
android()
jvm()
and
ios()
. The KMM project was generated by the KMM plugin and has
android()
iosArm64()
iosX64()
and
iosSimulatorArm64()
.
At first it didn’t work as the KMP lib wasn’t built for `iosSimulatorArm64()`:
ios()
doesn’t trigger it
So I added
iosSimulatorArm64()
to the KMP project and made a version but now I have this weird error
l
You have to ‘attach’ ios configuration to iosSimulator as well. Something like val iosMain by getting val iosSimulator by getting iosSimulator.dependOn { iosMain }
And don’t forget to do the same with iosTest
r
I did this
Copy code
sourceSets.getByName("iosSimulatorArm64Main") {
        dependsOn(sourceSets.getByName("iosMain"))
    }
I actually forgot for
iosTest
, but would that produce this error message? Seems unrelated
l
And instead of calling iosArm64() and iosX64(), call ios()
test source set should not produce this error (unless you run test), but at it anyway make more sense
r
I tried replacing these manual configurations of
iosArm64
and
iosX64
generated by the KMM plugin with the automatic
ios()
config but it didn’t change anything
l
Why you do prefer to get sourceset by string instead by property ?
sourceSets.getByName("iosSimulatorArm64Main")
val iosSimulator by getting
r
Because it’s actually defined in an extension function of
org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
in my
buildSrc
, and there seem to be no access to
sourceSets { }
there
But really on my KMP project side there doesn’t seem to be any problem, every arifacts I previously had were published, plus a new one for simulator arm64. It’s on a the consumer side that it seem to expect something else on the common artifact that I don’t understand
To be clear the KMM project was never able to use the KMP lib, it was just created, and then I realized the previously existing KMP lib wasn’t built for arm64 simulator and added it and that’s it.
l
So your lib (KMP lib)generate everything as expected (android / ios / jvm) but the consumer (KMM app) can’t take the right artifact ?
r
Yes. Previously the KMM build was complaining about the missing arm64 simulator artifact, which was normal as I never had it. And now I just added the arm64 simulator platform to the KMP lib, which was simple and worked right away, but the KMM shared module gives this error message when being built
l
And your KMM generated a ios-simulator artifact ?
r
You mean before adding the dependency? Yeah I guess, the build task was successful
l
Sorry your KMP lib
r
Yes I can see it in my maven repo
l
does it contains header file ? (some time the folder is generated but not files inside it)
r
Looks the same as arm64 and x64
m
What is the failing task? Is it something like
compileXyzKotlinMetadata
?
r
Yes
It was run after all the linkinkg tasks
m
I've been hit with this before, it's a HMPP thing
Unless you're trying to publish your lib, you can disable the task
Something like:
Copy code
tasks.configureEach {
  if (name.endsWith("KotlinMetadata")) {
    enabled = false
  }
}
(pardon if it's not 100% Gradle-lazy-idiomatic but I think it is?)
r
I see, I’ll try that. But isn’t it supposed to work? Is it maybe some kind of discrepancy between the
gradle.properties
configurations of the two projects?
m
TBH I'm a bit lost. It depends all the different project configurations, etc...
r
Interesting. Thanks for all the links!