https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

ribesg

03/05/2019, 10:23 AM
I have some problems with dependencies, what is the correct way, in a MPP, to use a MPP library as a dependency?
Copy code
sourceSets {

        val commonMain by getting {
            dependencies {
                api("mygroup:mympplib:0.0.1-SNAPSHOT")
            }
        }

        val androidMain by getting {
            dependencies {

            }
        }

        for (iosTarget in iosTargets) {
            getByName("${iosTarget.name}Main") {
                dependencies {

                }
            }
        }

    }
When I sync the gradle project in idea it prints
Copy code
Could not resolve mygroup:mylib:0.0.1-SNAPSHOT.
Could not resolve mygroup:mylib:0.0.1-SNAPSHOT.
But the configure is successful. When building, the references to the lib are not found, but IDEA sees everything and does’t give any error
r

Riccardo Montagnin

03/05/2019, 10:30 AM
Could you write here how you are including the library?
r

ribesg

03/05/2019, 10:32 AM
Copy code
sourceSets {

        val commonMain by getting {
            dependencies {
                api("mygroup:mylib:0.0.1-SNAPSHOT")
            }
        }

        val androidMain by getting {
            dependencies {

            }
        }

        for (iosTarget in iosTargets) {
            getByName("${iosTarget.name}Main") {
                dependencies {

                }
            }
        }

    }
This is the only code in the lib I’m importing (for now):
Copy code
val Http = HttpClient {
    install(JsonFeature) {
        serializer = KotlinxSerializer(Json.nonstrict)
    }
}
IDEA see’s
Http
, but it’s not found on compilation of Android Kotlin Debug sources
Replacing my last snippet with
Copy code
object HttpClientFactory {

    fun create(): HttpClient = HttpClient {
        install(JsonFeature) {
            serializer = KotlinxSerializer(Json.nonstrict)
        }
    }

}
and using that instead works
o

Oleg Yukhnevich

03/05/2019, 1:00 PM
"mygroupmympplib0.0.1-SNAPSHOT" - "groupnamevertsion" - this dependency style only work if you publish your module/library to maven or to maven local i think you need just
Copy code
api(project(":mympplib"))
r

ribesg

03/05/2019, 1:10 PM
My dependency is published.
2 Views