If I am using jetbrains resources, is it possible ...
# compose-ios
j
If I am using jetbrains resources, is it possible to somehow copy resource files from other modules than the shared module? My shared module has api dependency to a core module I would like to provide the resources. But seems like XCode build process is not copying them.
k
no. it is not implemented yet
but im working on that right now
j
Ah ok, hehe πŸ™‚ is it possible to hack this myself until its publicly available?
It looks like TIvi app doing this but I havent figure out how the heck he getting the font file resources into the build phases: https://github.com/chrisbanes/tivi/tree/main/common/ui/resources/fonts
k
it works for jvm and android now but with some limitations
j
Yes I solved it for jvm/Android myself already, its just the iOS part not working. Was thinking using api for the dependency + adding export to the iOS binary should help, but seems not.
Just curious how to get files from a gradle module into the Xcode building process of resources.
b
any luck with this @Joel Denke?
j
Yes, solved it πŸ™‚ Its ugly as hell, but its working πŸ˜„
I do it like this:
Copy code
class AndroidLibraryConventionPlugin : Plugin<Project> {
  override fun apply(target: Project) {
    with(target) {
      with(pluginManager) {
        alias(libs.plugins.android.library)
      }
      configureAndroid()
      android {
        sourceSets["main"].apply {
          manifest.srcFile("src/androidMain/AndroidManifest.xml")
          assets.srcDir("src/commonMain/composeResources/files/assets")
        }
      }
    }
  }
}
The key here is that I am adding a folder I know exist in files/assets, and pretend it should be in Android assets folder. Its very ugly as Jetbrains doing same for fonts. Where APK contains duplicates of same files. So having assets/fontfile.ttf and also files/font/fontfile.ttf Meaning increasing APK size a lot. Maybe a bug, not sure @Konstantin Tskhovrebov?
By doing this I can later on resolve files in Android by doing:
Copy code
actual class PlatformResource(
    private val path: String
): MyResource {

    @Composable
    override fun absolutePath(): String {
        return LocalContext.current.packageResourcePath + "/" + path
    }

    @Composable
    fun asUri(): Uri {
        val absolutePath = absolutePath()
        val file = File(absolutePath)
        return Uri.parse("file:///android_asset/${file.name}")
    }
}
Note that I am using file.name to get the basename and not the complete path here πŸ˜› I only using this for files NOT image, font or Jetbrains supported ways. So I sideloading my own resource resolving separate.
k
it is fixed in the latest dev build
j
Nice, whats fixed in this case? Files folder mirrored into assets or res/raw? Not sure if should put in res in Android or not. Do you know whats the most accurate way of doing it?
Just so I know what to expect when I update to next release πŸ™‚
k
I mean the font duplication is fixed
now fonts are copied only in the assets
j
And for all put into composeResources/files, where are those put in Android? πŸ™‚
k
as java resources
j
Types NOT being images/bitmaps, fonts etc I mean πŸ™‚
Java resources is not accessible in Android, tried that. If not having a new way of fetching those without using Reflections?
You cannot access files being in root APK Jar properly πŸ™‚ So if using that path, it will be new bugs I think.
Should be in APKroot/assets or APKroot/res/raw if I remember correct.
k
you are suppose to use the
Res.readBytes
for that
there is no an interop between android and compose resources
j
Yeah I know, hence my solution because Jetbrains not support what I need πŸ™‚ I need Res.getPath or Res.getUri for Android, so I can use the resource in third party libraries refer to my Res.file.video or such.
I think maybe using Java resources with reflections like getResource or getResourceBytes will violate som security things, but not sure to be honest. It feels like it should not be done that way, maybe for desktop JVM but not in Android. Investigated this a lot as had issues with put files into Java resources in same way Jetbrains compose resources library doing it not accessible as it should. Another problem is that @Preview not working with any of the Res resouces at all when having it in androidMain. If you would put fonts, images in the res folder qualifiers it wouldve worked.
k
Res.getUri is in my backlog πŸ‘Œ
❀️ 1
j
Nice! πŸ™‚ I hope I will be able to use that then, being able do like: Media3Item.fromUri(Res.video.getUri)) and such, and dito for NsUrl in iOS πŸ™‚
Until that happening, I use this hack/work around in Android / iOS πŸ™‚