Hello everyone, I'm looking for solution to access...
# multiplatform
s
Hello everyone, I'm looking for solution to access files in
desktopMain
sourceSet from
macosMain
sourceSet. https://stackoverflow.com/questions/78352474/kotlin-multiplatform-access-file-from-different-sourceset
r
Native (macOS) and JVM (desktop) targets are different platforms. You can't have one depending on the other. You should read the documentation on available platforms and targets to better understand what is what. https://kotlinlang.org/docs/multiplatform-discover-project.html https://kotlinlang.org/docs/multiplatform-hierarchy.html
s
Yep, I understand both are different platform. Suppose I wanted to check macOs bluetooth state is turned on or not. How can I do it while supporting jvm(desktop) ? Didn't found single resource for such use case
r
You need to do it twice.
d
One solution might be to create a source-set which which is included in the desktop and macOs source-set and write expect/actual implementation for whatever you like(If need to wrtie platform specific implementations) or just write common code for both platforms.
🤔 1
s
@Devanshu Pathsariya If possible can you share some demo code or link for the same ?
d
To create the source-set
Copy code
kotlin {
    sourceSets {

        val appleMain by getting
        val desktopMain by getting

        val desktopCommon by creating {
            appleMain.dependsOn(this)
            desktopMain.dependsOn(this)
        }
    }
}
Now you will have a new source-set and you can common code just like you would in
commonMain
source-set, only difference is code will be accessible only in
appleMain
and
desktopMain
and you need to write actual implementation in
appleMain
and
desktopMain
if you create a expect
👍 1
s
With this change I'm not able to access any NS* classes for macos platform
d
You can't access the classes of different platform in the desktopCommon source set it is the common source-set for appleMain and desktopMain. You can define expect/actual in the desktopCommon.
s
Ok, trying to creating expect actual
r
I don't think that's what you want. I'm pretty sure you just want your app to run on MacOS/Linux/Windows, in addition to Android & iOS, but in your project you did it twice. You need to choose between implementing your desktop app with Kotlin/JVM or with Kotlin/Native, or you'll just end up doing everything twice.
s
@ribesg I think to get the desired result have to add jvm and native target
🤷‍♂️ 1