https://kotlinlang.org logo
Title
a

Ali Albaali

08/02/2022, 1:54 PM
I have updated Kotlin version to 1.7.0 in my library, and when I publish it, everything works fine. However, using the library from another multi-platform project, I can’t access the common source set. If I downgrade to Kotlin 1.6.10, and publish it again (with a different version), I can access the common source set from the other project. Is there something has changed in 1.7.0 that I’m not aware of? Or is it somehow not related to the Kotlin version? More info in the thread.
t

Trevor Stone

08/02/2022, 1:55 PM
I believe 1.7.x libraries are only consumable by applications also on 1.7.x
a

Ali Albaali

08/02/2022, 1:57 PM
@Trevor Stone I’m using Kotlin 1.7.0 in both projects.
t

Trevor Stone

08/02/2022, 2:01 PM
Potentially https://kotlinlang.org/docs/multiplatform-hierarchy.html? There was a change in default behavior between 1.6.10 and 1.6.20
a

Ali Albaali

08/02/2022, 2:25 PM
Okay, I assume it is enabled by default for projects and libraries that are using version 1.7.0, correct? When adding this flag to the library:
kotlin.mpp.enableCompatibilityMetadataVariant=true
Gradle sync works fine. However, when I publish to mavenLocal, i get this error:
> Could not resolve all files for configuration ':kamel-core:metadataCompileClasspath'.
      > Could not resolve org.jetbrains.compose.ui:ui:1.2.0-alpha01-dev753.
When adding this flag to the project:
kotlin.mpp.hierarchicalStructureSupport=false
Gradle sync fails with this error:
kotlin.UninitializedPropertyAccessException: lateinit property targets has not been initialized
	at org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension.getTargets(KotlinMultiplatformExtension.kt:25)
What am I missing?
m

Mitchell Syer

08/02/2022, 2:39 PM
I looked at Kamel and I think its because your only publishing a jvm() sourceset, with no other sourceSets like android().
You can take a look at one of my forks for an example of setting up a compose library for Jvm and Android https://github.com/Syer10/compose-material-dialogs
a

Ali Albaali

08/02/2022, 2:50 PM
@Mitchell Syer If you see the images I have attached, they include android and desktop source sets. Meaning, I can use the library code from the android and desktop source sets (including the modules). The problem is with the
commonMain
source set, I can’t access the library from there with Kotlin version 1.7.0
t

Trevor Stone

08/02/2022, 2:50 PM
Can you post your gradle.properties file
a

Ali Albaali

08/02/2022, 2:51 PM
For library:
kotlin.code.style=official
android.useAndroidX=true
kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableCompatibilityMetadataVariant=true
For project:
kotlin.code.style=official
android.useAndroidX=true
#kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
kotlin.mpp.stability.nowarn=true
org.gradle.jvmargs=-Xmx4096m
kotlin.mpp.hierarchicalStructureSupport=false
m

Mitchell Syer

08/02/2022, 2:52 PM
@Ali Albaali I meant for Kamel-core, I think because it only uses jvm() that it cant be used for projects that use both jvm() and android() because it doesnt provide the required metadata
It probably worked fine for projects without HMPP because it was much simpler, HMPP is smarter/more advanced
t

Trevor Stone

08/02/2022, 2:54 PM
It looks like the library is just android and desktop though right, so just supporting jvm would be fine
to the initial question because I think I focused on the wrong thing "I have updated Kotlin version to 1.7.0 in my library, and when I publish it, everything works fine. However, using the library from another multi-platform project, I can’t access the common source set."
It syncs correctly but then when you are trying to consume it, code isn't accessible?
a

Ali Albaali

08/02/2022, 2:56 PM
@Mitchell Syer I understand. I should’ve mentioned that, using the kamel-core module works fine. I can access everything from it (e.g. Resource, KamelConfig, etc…). The problem is with kamel-image module, I can’t access lazyPainterResource or KamelImage composables from commonMain source set.
@Trevor Stone Yes, the library supports only android and desktop. If you check this link, you can see everything is uploaded correctly.
m

Mitchell Syer

08/02/2022, 2:58 PM
I was noticing that with my project as well, it uses Kamel and it builds fine, but the ide cant find anything in Kamel
a

Ali Albaali

08/02/2022, 2:59 PM
@Trevor Stone Only the code from
kamel-image
commonMain source set isn’t accessible. The code from
kamel-image
module with androidMain and desktopMain is accessible and working fine.
t

Trevor Stone

08/02/2022, 3:02 PM
in your project consuming the library how are you defining the dependencies
a

Ali Albaali

08/02/2022, 3:03 PM
val commonMain by getting {
    dependencies {
        api(compose.runtime)
        api(compose.foundation)
        api(compose.material)
        api(compose.material3)
        api(compose.materialIconsExtended)
        implementation(project(":data"))
        api("org.jetbrains.kotlinx:kotlinx-datetime:0.3.3")
        api("com.alialbaali.kamel:kamel-image:0.4.21")
        api("com.halilibo.compose-richtext:richtext-commonmark:0.10.0")
    }
}
t

Trevor Stone

08/02/2022, 3:04 PM
why is
kotlin.mpp.hierarchicalStructureSupport=false
in your project
a

Ali Albaali

08/02/2022, 3:05 PM
I tried to disable it to see if it works. It wasn’t there before.
You can try to create new project by using the default template, add the library, and you’ll see the problem is there.
a

andylamax

08/03/2022, 7:37 AM
I am also having this very same problem. I have battled with it all night, to no avail
t

Trevor Stone

08/03/2022, 1:30 PM
I tired playing with it more last night and was able to build the project with code in the common source set, but the IDE wouldn't resolve correctly and showed errors
a

Ali Albaali

08/03/2022, 3:23 PM
@Trevor Stone does it show the
kamel-image
commonMain package in the “External libraries” view?
It does build without any errors, so I think the problem is with Kotlin IDE plugin, it is not identifying the commonMain source set.