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

Soundlicious

12/12/2023, 10:25 AM
Anyone has a good tutorial for shared resources (drawable, strings, colors) ? Moko isn't working with kotlin 1.9+. I tried to follow https://www.netguru.com/blog/kotlin-multiplatform-resources but i don't have a resourceGeneratorTask.
j

Jhaman das

12/12/2023, 10:43 AM
What issue you are facing? As i am also using moko its working fine as excepted.
1
s

Soundlicious

12/12/2023, 10:44 AM
With which kotlin version ? I can't get the MR object generated
j

Jhaman das

12/12/2023, 10:45 AM
I am using
kotlin 1.9.20
🤔 1
s

Soundlicious

12/12/2023, 10:46 AM
And it worked immediately following the installation tuto from the readme ?
j

Jhaman das

12/12/2023, 10:48 AM
No. But you need to add
dependsOn(commonMain)
inside the android block in shared
build.gradle
file
s

Soundlicious

12/12/2023, 10:49 AM
Yeah i tried that, spent my afternoon yesterday trying all the fixes i could find but nothing worked 🥲
😟 1
Turns out I just might not get the idea out of it... MR object exist but only outside commonMain packages
So I just need to changed my shared data class and not expect an ImageResources in it.
@Jhaman das Would it be possible to see your build.gradle ?
r

Raed Ghazal

12/12/2023, 12:46 PM
works for me on kotlin 1.9.* commonMain dependencies
Copy code
api("dev.icerock.moko:resources:0.23.0")
api("dev.icerock.moko:resources-compose:0.23.0")
iOS targets
Copy code
framework {
    baseName = "shared"
    isStatic = true
    export("dev.icerock.moko:resources:0.23.0")
}
had to also do that
Copy code
val androidMain by getting {
     sourceSets {
         getByName("androidMain").kotlin.srcDirs("build/generated/moko/androidMain/src")
}
and
Copy code
val iosX64Main by getting {
    resources.srcDirs("build/generated/moko/iosX64Main/src")
}
val iosArm64Main by getting {
    resources.srcDirs("build/generated/moko/iosArm64Main/src")
}
val iosSimulatorArm64Main by getting {
    resources.srcDirs("build/generated/moko/iosSimulatorArm64Main/src")
}
had to also do that
this part found in one of the issues in their github as a temp fix until they fix their code
s

Soundlicious

12/12/2023, 2:09 PM
And you can access MR in the commonMain module ? I still have no build for the resources there, just the expect MR
r

Raed Ghazal

12/12/2023, 2:22 PM
yes
no build for the resources there
even after you rebuild the app?
s

Soundlicious

12/12/2023, 2:24 PM
Yep, even after rebuilding, still no resources in commonMain, just the expect MR object.
Quite frustrating
r

Raed Ghazal

12/12/2023, 2:25 PM
are you sure you’re using the latest version?
had similar issues in the past
s

Soundlicious

12/12/2023, 2:25 PM
mokoResources = "0.23.0"
r

Raed Ghazal

12/12/2023, 2:26 PM
hmm
can you show your ”
Copy code
multiplatformResources
” block?
s

Soundlicious

12/12/2023, 2:32 PM
I only left the mandatory part :
Copy code
multiplatformResourcesPackage = "dev.nar.resources" // required
1
Ah! it actually work, just the reference can't be find by the autocomplete
😅 1
Spent 2 days battling with it, because of that 😮‍💨
r

Raed Ghazal

12/12/2023, 3:10 PM
ah shit 😄 good to know you fixed it
s

Soundlicious

12/12/2023, 3:11 PM
Yep, thanks for the help, I'll finally be able to start my project... until the next problem 😄
🙌 1
r

Raed Ghazal

12/12/2023, 3:11 PM
trust me, you will face many.. 😄
but feel free to ask
s

Soundlicious

12/12/2023, 3:13 PM
Oh I'm sure I'll, even with a relatively easy to do app ^^ Won't hesitate to ask thanks
1
👀 1
5 Views