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

suresh

09/19/2023, 5:35 AM
Hi folks, according to this doc , adding another kmp project to commonMain is enough to add the dependency. But somehow the classes from common modules are not accessible to native targets ( nativeMain, macosMain, appleMain etc) . I am using latest 1.9.20-Beta version with
DefaultHierarchyTemplate
. Tried all the usual stuffs (like clean, clear cache, restart etc). Any idea whats the issue here?
here is my build config
Copy code
plugins {
  `kotlin-multiplatform`
}
kotlin {
  
  macosArm64 {
    binaries { executable(listOf(DEBUG, RELEASE)) { entryPoint = "main" } }
    compilations.configureEach {
      compilerOptions.configure { freeCompilerArgs.add("-Xallocator=custom") }
    }
  }
  applyDefaultHierarchyTemplate()

  sourceSets {
    commonMain {
      dependencies {
        api(projects.common)
      }
    }
  }
}
And i am trying to access those common module classes from nativeMain and that’s failing.
c

Cherrio LLC

09/19/2023, 3:01 PM
Did you declare the other targets
sorceset
?
s

suresh

09/19/2023, 3:04 PM
you mean some thing like ?
Copy code
sourceSets {
    nativeMain {
    }
    // or macosMain etc
}
with this config, i was expecting the shared module classes (projects.common) should be available on in commonMain sourceset
this is working when i use jvm and js targets.. somehow not for native one.
c

Cherrio LLC

09/19/2023, 3:16 PM
Yeah sometimes you have to use
dependsOn
to link it. As quoted in the docs:
Some dependencies for source sets are set by default. You don't need to specify any
dependsOn
relations manually
More here
s

suresh

09/19/2023, 3:18 PM
correct.. the new
applyDefaultHierarchyTemplate()
should take care of that part - https://kotlinlang.org/docs/whatsnew-eap.html#create-your-project-easier
it’s not working even if i explicitly add dependsOn
c

Cherrio LLC

09/19/2023, 3:35 PM
True just read the docs.
Did you migrate or its a new project based on 1.9.20-beta?
s

suresh

09/19/2023, 3:42 PM
it’s a new sample project based on 1.9.20-Beta
c

Cherrio LLC

09/19/2023, 3:57 PM
Try comment out this
Copy code
applyDefaultHierarchyTemplate()
According to the docs:
If you want to have additional source sets that the default hierarchy template doesn't provide, for example between JS and the JVM, adjust the hierarchy by reapplying the template explicitly with
applyDefaultHierarchyTemplate()
and configuring additional source sets manually as usual with
dependsOn()
s

suresh

09/19/2023, 5:28 PM
i think
applyDefaultHierarchyTemplate()
is enabled by default. Same issue when removing that config
2 Views