icerockdev / moko-resources

Resources access for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.04k stars 118 forks source link

Plugin not generating Strings #481

Open Deaths-Door opened 1 year ago

Deaths-Door commented 1 year ago

I have got in module build.gradle

    id("dev.icerock.mobile.multiplatform-resources") //Version in settings.gradle
    multiplatformResources {
        multiplatformResourcesPackage = "com.deathsdoor.chillbackmusicplayer.resources"
    }

and in the root build.gradle


buildscript {
    repositories {
        google()
        gradlePluginPortal()
        mavenCentral()
    }
    dependencies {
        classpath("dev.icerock.moko:resources-generator:0.22.0")
    }
}

and also in commonMain/resources/MR/base.xml which is same as default one in doc . The build tasks runs but doesn't generate strings and in the generated files the dev.icerock.moko.... import is unresolved which leads to unable to build and run the project , how do i fix this , i followed the tutorial but i get this error

Alex009 commented 1 year ago

hi. to resolve unresolved imports you should add dependency as described in readme. check samples.

reason of not generated strings only that plugin not see resources that he search. compare your config with samples.

https://github.com/icerockdev/moko-resources/blob/master/samples/resources-gallery/mpp-library/build.gradle.kts https://github.com/icerockdev/moko-resources/blob/master/samples/resources-gallery/mpp-library/src/commonMain/resources/MR/base/strings.xml

Deaths-Door commented 1 year ago

Thank you , i forgot to add moko.resources to my common module and after that a clean was needed to solve my issue and generate the strings , also what exactly is the purpose of the resources-compose module , as we can already get the string via the base module , is there any specific use case for the resources-compose module ? Also is there a way to get the string localized in commonMain instead of platform specific impl

Alex009 commented 1 year ago

resources-compose module have @Composables for compose-multiplatform. you can't get localized string in commonMain because for android resources reading require Context. if you use compose multiplatform you can use stringResource in commonMain - Context will be readed in actual android implementation from LocalContext

comm1x commented 2 weeks ago

Jetpack Compose Resources removed this limitation and allows to read strings from common-code.