I'm having some trouble with `actual/expect` class...
# kotlin-native
j
I'm having some trouble with
actual/expect
classes in a multiplatform project using K/N for iPhone target. I'm running the gradle build task
compileKonan
and the compiler generates an error when compiling one my
actual
class definitions.
Copy code
UUID.kt:3:14: error: actual class 'UUID' has no corresponding expected declaration
    actual class UUID {
My gradle.build file for the native project
Copy code
apply plugin: 'konan'

konan.targets = ["iphone", "iphone_sim"]

konanArtifacts {
    library('native') {
        enableMultiplatform true
        commonSourceSet 'main'
        srcDir 'src/main/kotlin'
    }
}

dependencies {
    expectedBy project(':common')
}

task test(dependsOn: run)
Any thoughts on how I might have misconfigured my gradle build? I'm using v0.6 kotlin-native plugin for MacOS. My
actual/expect
declarations work in my common and android modules in the multiplatform project, not in the native build currently. My class is defined in the common module as such:
Copy code
package some.package.name

expect class UUID {
    companion object {
        fun randomUUID() : UUID
    }
}
s
My konanArtifacts looks like
Copy code
konanArtifacts {
    framework('native') {
        enableMultiplatform true
    }
}
The source set default is
main
so you shouldn't need that. Also the
srcDir
is redundant since that should be the default. You should use
framework
for iOS since that will build a dynamic library.
j
I removed those redundancies and tried
framework
but these changes don't address my compiler error.
s
Do you have a
buildScript
block with a dependency on the
kotlin-native-gradle-plugin
?
Copy code
buildscript {
    repositories {
        mavenCentral()
        maven {
            url  "<https://dl.bintray.com/jetbrains/kotlin-native-dependencies>"
        }
    }

   dependencies {
        classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
   }
}
j
Yes, that doesn't affect the build error. The kotlin native plugin is loaded and building, but this is specific to the issue of resolving the
expect
declaration in the common module.
s
Is there perhaps a typo in the package declaration of the actual class for iOS?
j
Yeah, I checked that as well. Packages are the same. I also tried to recreating the folder structure similar to Java/Android package. Not sure if packages are even resolved in Kotlin native.
Know of any example multiplatform code that uses this feature?
r
👍 1
s
I followed this example to update a project I started in K/N 0.5 to 0.6. It's working for me. I'm able to have expected classes and actual classes in K/N.
j
Thanks guys. I was able to figure it out. I had imported gradle incorrectly into Android Studio and it wasn't aware of the other projects. Builds on the command line do work.
👍 1
t
You could also have a look at this open source repo: https://github.com/novoda/spikes/tree/master/game-of-life-multiplatform
👍 1
j
I'm still having trouble with building in Android Studio. I've added a Gradle build target using the top level module and a build task of 'native:konanCompile'. The build fails to resolve the
actual
declarations. Command line builds work fine. Are you guys using Jetbrains IDEs for compilation of multiplatform projects?
t
yes, I am using IntelliJ. did you try that?
s
I'm using command line most of the time but sometimes building in AS as well. My build task looks in AS looks like
:native:build
j
Latest IntelliJ CE fails miserably... there's some incompatibility with
com.android.tools.build:gradle:3.+
. I've tried
:native:build
and that doesn't work either for me. What version of AS are you using? I'm using v3.0.1.