Hey guys, I am reading this <Creating your first K...
# multiplatform
v
Hey guys, I am reading this Creating your first Kotlin Multiplatform library. I updated the maven-publish Gradle plugin. After that I run the command .
/gradlew publishToMavenLocal
. I am getting error
Execution failed for task ':generateMetadataFileForIosArm64Publication'.
> java.io.FileNotFoundException: /Users/vmodi/IdeaProjects/AndroidModule/build/classes/kotlin/iosArm64/main/klib/AndroidModule.klib (No such file or directory)
Copy code
plugins {
    kotlin("multiplatform") version "1.6.20"
    id("maven-publish")
}

group = "me.vmodcleari"
version = "1.0.0"

repositories {
    mavenCentral()
}

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        withJava()
        testRuns["test"].executionTask.configure {
            useJUnitPlatform()
        }
    }
    ios()

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting
        val iosMain by getting
        val iosTest by getting
    }
}
k
do you use macos? right?
v
Yes I use mac os @Konstantin Tskhovrebov
a
Hi! Let me try to help you. Can you share your
settings.gradle.kts
too. With
gradle.properties
? And If I see right, you are using MacOS on M1 architecture?
v
Give me one minute I'll share you the file. I am on
macos
with
intel
chip.
👌 1
a
I'm going to verify it on my machine and let you know If I find anything suspicious
v
setting.gradle.kts
Copy code
rootProject.name = "AndroidModule"
gradle.properties
Copy code
kotlin.code.style=official
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
my project structure
yeah sure, thanks
a
Cool. I'm able to reproduce your issue. Give me some time to think about it.
Perhaps I'll ask you to report a bug in YouTrack. If it is indeed a bug. Anyway I'll try to find a workaround for you as well.
but didn't get response
a
Thank you.
👍 1
Ok clear. I think you need to have at least 1 declaration in the source files for each target in order to be able to publish library. So Kotlin Gradle Plugin assumes that libraries for all targets are not empty. It looks like you don't have any code in commonMain nor iosMain. Add some dummy class or function in commonMain source set and it should fix your problem. I'll update your issue that we need to fix such cases and either warn users that they are about to publish empty libraries, or just allow to do so without any errors/warnings.
v
Oh yes it fixed by adding class in commanMain
Thank you so much
a
You're welcome. Sorry the delay. I simply missed your initial message, could have helped you faster 🙂
v
yeah it really quick fix. Thanks you so much
you guys are amazing
a
Thank you for your kind words. May I ask you why you need such setup where only jvm target has code and other are empty? Are you migrating your jvm library to multiplatform? Or is it something else?
v
Actually I have two project one is android and other one is iOS. I want to use kmm to connect both platform. I learned my basic stuffs to connect both platform. I give demo to my supervisor. He suggested me to use kmm module as a library. So I started learning, how to make kmm as library and I found this post. I created a project in intellj and run that command and getting that error. I don't know about jvm because it giving me suggestion, when I am creating a new project.
Is jvm and android are same?
a
Is jvm is same as android?
roughly, yes. Android can consume and use some jvm libraries. But you can also publish pure android libraries. But that is a bit complex setup as you need to use android-library plugin together with kotlin multiplatform. There is some tutorials on the Internet how to do that.
👍 1