coil-kt/coil

Compose Multiplatform Resources loaded with Res.getUri don't work on Windows

Open

#2833 aperta il 9 feb 2025

Vedi su GitHub
 (6 commenti) (5 reazioni) (0 assegnatari)Kotlin (757 fork)batch import
help wanted

Metriche repository

Star
 (11.779 star)
Metriche merge PR
 (Merge medio 20h 14m) (28 PR mergiate in 30 g)

Descrizione

Discussed in https://github.com/coil-kt/coil/discussions/2824

Originally posted by nevrozza February 1, 2025 Hi! I program on a macbook, but now I've built a project for windows and now I don't have icons/images... (On other platforms (macOS, iOS, Android, WASM, JS) everything is OK).

/*"jar:file:/Users/nevrozq/Code/PansionApp/common/utils-compose/build/libs/utils-compose-jvm.jar!/composeResources/pansion/drawable/icons/screwdriver-wrench-solid.svg"*/
val uri = Res.getUri("drawable/icons/${path}")
AsyncImage(
    ImageRequest.Builder(LocalPlatformContext.current)
        .data(uri)
        .build(),
        // other params
)

Throws:

java.lang.IllegalStateException: Unable to create a fetcher that supports: jar:file:/C:/Users/harla/OneDrive/Desktop/PansionApp/composeApp/build/compose/binaries/main-release/app/PansionApp/app/utils-compose-jvm-441ba4d5932399cabbfe401536893dcf.jar!/composeResources/pansion/drawable/icons/trophy-solid.svg

I guess the problem is that the project is multi-module and Res.getUri("drawable/icons/${path}") returns svg from a jar file. However, it still works on other platforms

Very important: If I use url link from internet or put path to picture (not in jar) it works...

So... There is a crutch solution! Make a separate Windows-only folder with resources and transfer it simply as a string uri = "resources\\drawable\\icons\\${path}"...... But I still believe there is a better solution.

Thanks!

Guida contributor