Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource image not found on platforms #39

Open
HLCaptain opened this issue Nov 3, 2023 · 6 comments
Open

Resource image not found on platforms #39

HLCaptain opened this issue Nov 3, 2023 · 6 comments

Comments

@HLCaptain
Copy link

HLCaptain commented Nov 3, 2023

I placed my resources under commonMain besides the kotlin directory, inside the libres folder as stated in the README.md.

When trying to run my Compose Multiplatform JVM based desktop app, I get this exception when trying to get the painterResource for my Image composable:

Exception in thread "main" java.lang.IllegalArgumentException: Resource images/flower_image.jpg not found
	at androidx.compose.ui.res.ClassLoaderResourceLoader.load(Resources.desktop.kt:122)
	at androidx.compose.ui.res.Resources_desktopKt.openResource(Resources.desktop.kt:71)
	at androidx.compose.ui.res.PainterResources_desktopKt.rememberBitmapResource(PainterResources.desktop.kt:137)
	at androidx.compose.ui.res.PainterResources_desktopKt.painterResource(PainterResources.desktop.kt:70)
	at androidx.compose.ui.res.PainterResources_desktopKt.painterResource(PainterResources.desktop.kt:57)
	at io.github.skeptick.libres.compose.ActualsKt.painterResource(actuals.kt:9)
	at io.github.skeptick.libres.compose.PainterResourceKt.painterResource(PainterResource.kt:11)

Similar issue happens when running on JS based platform:

When requesting the flower_image.jpg, the GET request returns with a 404 (not found) status.

Platforms affected (Android works fine):

  • JVM
  • JS

Versions:

  • Kotlin: 1.9.20
  • Libres: 1.2.0
  • Compose Multiplatform: 1.5.10
  • Android Gradle Plugin: 8.2.0-rc02

I suspect, that resources' path has been changed recently, either with newer Kotlin or Compose Multiplatform versions.

@Skeptick
Copy link
Owner

Skeptick commented Nov 4, 2023

Path to your image looks like commonMain/libres/images/flower_image.jpg?

@HLCaptain
Copy link
Author

HLCaptain commented Nov 4, 2023

Yes, it does. Also, string resources are working fine on all platforms.

@HLCaptain
Copy link
Author

I will soon make an open-source repository so you may reproduce the problem. @Skeptick

@HLCaptain
Copy link
Author

You can clone this branch to reproduce the problem.

@Skeptick
Copy link
Owner

Skeptick commented Dec 3, 2023

This issue isn't related to Libres.
Typical JVM-application build doesn't include resources from other modules.
You need to explicitly configure dependency or build a fat JAR.
Or you can use compose plugin and add this code:

// desktop/build.gradle.kts
compose.desktop {
    application {
        mainClass = "com.example.demo.MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "desktop"
            packageVersion = "1.0.0"
        }
    }
}

And run via ./gradlew desktop:run

@HLCaptain
Copy link
Author

Thanks, will test this out later. I may do a PR about this though to update docs and clarify some things about resource management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants