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

Nikolay Kasyanov

04/09/2020, 6:53 AM
Hey folks, is anyone else seeing this? While upgrading our project to 1.3.71, I also switched to the recommended syntax of defining iOS source sets, replacing this:
Copy code
iosX64Main { ...dependencies... }
iosArm64Main {
    dependsOn iosX64Main
}
with this:
Copy code
ios {
    iosArm64Main.dependsOn it
    iosX64Main.dependsOn it

    ...dependencies...
}
moving iOS-only source files from
iosX64Main
to
ios
folder accordingly. Now all imports starting with
platform.
are highlighted red in the IDE all the time, builds fine though. Is this a known issue?
For the record, IDE plugin version is
1.3.71-release-IJ2019.3-1
a

Artyom Degtyarev [JB]

04/09/2020, 9:27 AM
Hello! Can you show a bit more on your project’s current structure? IIRC,
ios{…}
shortcut should create an
src/iosMain/kotlin
folders, not an
/ios
one.
n

Nikolay Kasyanov

04/09/2020, 9:30 AM
having the same experience with
iosMain
folder on another project
sure, I’ll try
a

Artyom Degtyarev [JB]

04/09/2020, 9:32 AM
I’m also confused a bit with this
.dependsOn
constructions, the purpose of the shortcut was to get rid of this.
n

Nikolay Kasyanov

04/09/2020, 9:43 AM
@Artyom Degtyarev [JB] oh yes, I might’ve misinterpreted the docs. Is there any reference `build.gradle`/`build.gradle.kts` example to have a look at?
I’m looking at https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#target-shortcuts and can’t figure out how to replace the
sourceSets.iosMain
example with the new
ios
shortcut.
a

Artyom Degtyarev [JB]

04/09/2020, 9:53 AM
I’m not informed on any sample scripts, maybe some of them can be found across the community. We had some problems with this feature(see this issue for example). To use the shortcut, just change your target’s declaration with the
ios{...}
, with saving all contents of the original
ios<Arm | X>64
block. The only thing the shortcut does is adding both targets internally, making their source sets depending on the new
iosMain
and that’s all. So, there is no need to specify them explicitly as you’ve done.
n

Nikolay Kasyanov

04/09/2020, 9:56 AM
I tried looking at open source examples but couldn’t yet find any using the new shortcut.
Thanks, I’ll check out the issue and try what you’ve suggested.
turns out
kotlin.mpp.enableGranularSourceSetsMetadata=true
is a must for it to work
👍 1
o

Olenyov Kirill

04/09/2020, 11:26 AM
@Nikolay Kasyanov Did you find a solution? enableGranularSourceSetsMetadata didn’t help me:(
a

Artyom Degtyarev [JB]

04/09/2020, 11:29 AM
hi, @Olenyov Kirill! Are you also facing highlighting issues when using
ios
target shortcuts?
o

Olenyov Kirill

04/09/2020, 11:30 AM
Yeah, all import platform.* are red. But building is fine..
n

Nikolay Kasyanov

04/09/2020, 11:35 AM
aside of
kotlin.mpp.enableGranularSourceSetsMetadata=true
I changed the structure like this:
Copy code
kotlin {
    ios()

    sourceSets {
        ...
        iosMain {
            // no explicit dependsOn calls needed

            
        }
        ...
    }
}
@Olenyov Kirill have you restarted IDEA after adding
kotlin.mpp.enableGranularSourceSetsMetadata=true
to
gradle.properties
?
not sure why reimporting/reloading project wasn’t helping
(restarting might be a nuclear option, closing and reopening the project might do too)
o

Olenyov Kirill

04/09/2020, 11:41 AM
After adding kotlin.mpp.enableGranularSourceSetsMetadata=true I have a problems not only with platform dependings. But also with kotlinx.* Now all are red)) And I see in log: There is a library attached to the project that was compiled with a newer Kotlin/Native compiler and can’t be read in IDE: “common.klib” at $project/common/build/classes/kotlin/iosX64/main/common.klib Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version 1.3.61. Then rebuild the project and re-import it in IDE. I have AS 3.6.2. May it be the root cause?
a

Artyom Degtyarev [JB]

04/09/2020, 11:44 AM
Are your project Kotlin version and an IDE’s Kotlin plugin version synchronized?
o

Olenyov Kirill

04/09/2020, 11:50 AM
How to check IDE’s plugin version?
a

Artyom Degtyarev [JB]

04/09/2020, 11:51 AM
Tools > Kotlin > Configure Kotlin Plugin Updates
IIRC.
o

Olenyov Kirill

04/09/2020, 11:53 AM
I see a newer version for AS. I’ll to install..
Fixed!
🎉 3
n

Nikolay Kasyanov

04/09/2020, 12:05 PM
@Artyom Degtyarev [JB] thanks for your help!
o

Olenyov Kirill

04/09/2020, 12:06 PM
Yeah, thanks!
@Artyom Degtyarev [JB] Found another issue. With enableGranularSourceSetsMetadata=true all my “actual” methods in androidMain are red now:(
a

Artyom Degtyarev [JB]

04/10/2020, 10:48 AM
Seems related to (https://youtrack.jetbrains.com/issue/KT-33809). There is a workaround in the discussion, please give it a try.
o

Olenyov Kirill

04/10/2020, 10:51 AM
Yeah, it works. Thanks!
2 Views