Do you use platform plugin? for example `kotlin-pl...
# multiplatform
g
Do you use platform plugin? for example
kotlin-platform-jvm
instead of
kotlin
in Gradle?
y
Yes i do
Copy code
apply plugin: 'kotlin-platform-jvm'

repositories {
    jcenter()
    maven { url "<http://kotlin.bintray.com/kotlinx>" }
}

sourceSets {
    main.kotlin.srcDirs += 'main/'
    test.kotlin.srcDirs += 'test/'
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    expectedBy project(":booking:framework")

    testCompile "junit:junit:4.12"
    testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}
g
expectedBy dependency and
actual
declaration should be enough
What is your error message? maybe you forgot to implement some declarations
y
Here s my expect declaration:
Copy code
expect class Platform(
        url: String
) {
    fun get():String
}
and here is my actual:
Copy code
actual class Platform actual constructor(
        private val url: String
) {
    actual fun get():String {
        return "KN-Android $url"
    }
}
I’m using one from an example project i found online
And my error says
Expected class Platform has no actual declaration in module
And vice versa:
Actual class 'Platform' has no corresponding expected declaration
g
hmm, just for test, try to use the same actual declaration with primary constructor, maybe this is the problem
y
Sorry what do you mean? I’m new to kotlin as well
g
try:
Copy code
actual class Platform(url: String) {
    actual fun get():String {
        return "test"
    }
}
y
Same error is still occurring
g
Maybe you could show some sample project that reproduces this problem
y
I’ll dm you a zip file
g
just post to Github
y
I’ve messaged you the link
g
Your package is different
Class must have the same package in expect and actual declaration
g
It is just the compiler that raises the error or also idea? If you have the error in idea, just use the quickfix.
y
Yes it worked! Thankyou 🙂
I’m still relatively new to Android/Kotlin
g
It’s Kotlin multi-platform rule, class name is not enough, you should use fully qualified name of a class package + name
i
Also, if you use multiple source sets in gradle project, then the corresponding expects and actuals should be in the same named source sets. For example, actuals from main source set of platform project implement expects from main source set common project.
a
@ilya.gorbunov So, when the
main
of
expect common
module is located in
./common/main/
, while the
main
of
actual platform
module resides in
./src/main/java
. The building won’t work? Even I set the
sourceSets
in
build.gradle
? These relative path of the 2 need to match even in the different project?
i
@albertgao No, the binding works by sourceset name. The directory layout inside the sourceset can be arbitrary