Hi! I’m trying to share resources from a compose m...
# multiplatform
j
Hi! I’m trying to share resources from a compose multiplatform module to native apps. The generated val/classes (build/generated/compose/resourceGenerator/kotlin/commonMainResourceAccessors) are
internal
by default
Copy code
internal val Res.drawable.myDrawable: DrawableResource
  get() = CommonMainDrawable0.myDrawable
The idea is to have a
commonResource
module in my project that can be used from existing android apps are from a widget module for example. Android widgets with compose uses the Glance framework, which make shared UI unusable. But I’m trying to expose the resources so I don’t need to reimport them locally in the module. Or am I missing something?
j
In your build script file:
Copy code
compose.resources {
    publicResClass = true
}
will make them non-internal anymore.
j
Nice, thanks!
j
There are more options there (like package) but I can't find the docs for it right now
j
don't you need to update gradle to specify what shared files will be included on the Native side? For instance on iOS, I would have to add the file to the 'Copy Bundle Resources' section Build Settings.
j
From my android app, I can see Android Studio locate the generated code but it gives me this error
Cannot access class ‘org. jetbrains. compose. resources. DrawableResource’. Check your module classpath for missing or conflicting dependencies
I did add
implementation(project(":commonResources"))
in my build.gradle of the android app, and it seems to resolve the dependency since I don’t get any error from gradle