Hi! I want to use KMP in react project. Here is my...
# multiplatform
n
Hi! I want to use KMP in react project. Here is my build gradle:
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("dev.petuska.npm.publish") version "3.4.0"
}

kotlin {
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()


    js(IR) {
        binaries.library()
        browser()
    }

    cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0"
        ios.deploymentTarget = "14.1"
        framework {
            baseName = "kotlinmultiplatformsharedmodule"
        }
    }
    
    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting
        val androidTest by getting
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

npmPublish {
    registries {
        register("npmjs") {
            uri.set(uri("<https://registry.npmjs.org>")) //
            authToken.set("obfuscated")
        }
    }
}

android {
    namespace = "com.example.kotlinmultiplatformsharedmodule"
    compileSdk = 32
    defaultConfig {
        minSdk = 21
        targetSdk = 32
    }
}
I also use https://github.com/mpetuska/npm-publish, but i still got ‘Node Distributions at https://nodejs.org/dist’ was added by unknown code’ when try to build. If I add KMP to react project without build it will not recognize the import module when run the app. Do you guys have any ideas for this issue?
a
I've found for K/JS projects and Gradle builds that use the Gradle Node Plugin you need to manually declare the Node download source as a repo (and the same for Yarn), and then the warning stops https://github.com/krzema12/snakeyaml-engine-kmp/blob/1a15ee41dc591e71d4383816b9763498a790d3b2/settings.gradle.kts#L17-L40
n
Many thank @Adam S. I tried with the above repos but I keep getting error: CustomMessageMissingMethodException: Could not find method ivy() for arguments [https://nodejs.org/dist/. This is my setting gradle:
Copy code
pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        // Declare the Node.js & Yarn download repositories
        exclusiveContent {
            forRepository {
                ivy("<https://nodejs.org/dist/>") {
                    name = "Node Distributions at $url"
                    patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
                    metadataSources { artifact() }
                    content { includeModule("org.nodejs", "node") }
                }
            }
            filter { includeGroup("org.nodejs") }
        }

        exclusiveContent {
            forRepository {
                ivy("<https://github.com/yarnpkg/yarn/releases/download>") {
                    name = "Yarn Distributions at $url"
                    patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") }
                    metadataSources { artifact() }
                    content { includeModule("com.yarnpkg", "yarn") }
                }
            }
            filter { includeGroup("com.yarnpkg") }
        }

        ivy("<https://github.com/>") {
            name = "GitHub Release"
            // used to download YAML Test Suite data from GitHub
            patternLayout {
                artifact("[organization]/[module]/archive/[revision].[ext]")
                artifact("[organization]/[module]/archive/refs/tags/[revision].[ext]")
                artifact("[organization]/[module]/archive/refs/tags/v[revision].[ext]")
            }
            metadataSources { artifact() }
        }
    }
}
rootProject.name = "kmmsharelib"
include ':appkmm'
include ':kotlinmultiplatformsharedmodule'
Can you give me some advices?
a
ah you're using the Groovy DSL - the script I shared was using the Kotlin DSL. I don't use the Groovy DSL, although it is similar, so you'll either have to convert my example from Kotlin to Groovy, or convert your
settings.gradle
to
settings.gradle.kts
:)
n
@Adam S I tried to convert my settings.gradle to settings.gradle.kts but it keep showing : cannot determine the dependencies of task ‘kotlinmultiplatformsharedmodulecompileKotlinJs’ Here is my setting.gradle.kts file:
Copy code
pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()

        // Declare the Node.js & Yarn download repositories
        exclusiveContent {
            forRepository {
                ivy("<https://nodejs.org/dist/>") {
                    name = "Node Distributions at $url"
                    patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
                    metadataSources { artifact() }
                    content { includeModule("org.nodejs", "node") }
                }
            }
            filter { includeGroup("org.nodejs") }
        }

        exclusiveContent {
            forRepository {
                ivy("<https://github.com/yarnpkg/yarn/releases/download>") {
                    name = "Yarn Distributions at $url"
                    patternLayout { artifact("v[revision]/[artifact](-v[revision]).[ext]") }
                    metadataSources { artifact() }
                    content { includeModule("com.yarnpkg", "yarn") }
                }
            }
            filter { includeGroup("com.yarnpkg") }
        }

        ivy("<https://github.com/>") {
            name = "GitHub Release"
            // used to download YAML Test Suite data from GitHub
            patternLayout {
                artifact("[organization]/[module]/archive/[revision].[ext]")
                artifact("[organization]/[module]/archive/refs/tags/[revision].[ext]")
                artifact("[organization]/[module]/archive/refs/tags/v[revision].[ext]")
            }
            metadataSources { artifact() }
        }
    }
}

rootProject.name = "kmmsharelib"
include(":appkmm")
include(":kotlinmultiplatformsharedmodule")
Can you help to fix this issue?
a
hi, I'm not sure what might cause the error
cannot determine the dependencies of task ‘:kotlinmultiplatformsharedmodule:compileKotlinJs’
- it looks like a separate issue that you'll need to provide more information about. I recommend a new thread :) It would help to see the full error, and what Gradle/Kotlin version you're using.
btw you probably don't want to add the
ivy("<https://github.com/>")
repo, unless you're planning to download source code from GitHub using Gradle