diff --git a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/Resource.android.kt b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/Resource.android.kt index 18190a95e4..62a868e249 100644 --- a/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/Resource.android.kt +++ b/components/resources/library/src/androidMain/kotlin/org/jetbrains/compose/resources/Resource.android.kt @@ -13,7 +13,8 @@ actual fun resource(path: String): Resource = AndroidResourceImpl(path) @ExperimentalResourceApi private class AndroidResourceImpl(path: String) : AbstractResourceImpl(path) { override suspend fun readBytes(): ByteArray { - val resource = (::AndroidResourceImpl.javaClass.classLoader).getResourceAsStream(path) + val classLoader = Thread.currentThread().contextClassLoader ?: (::AndroidResourceImpl.javaClass.classLoader) + val resource = classLoader.getResourceAsStream(path) if (resource != null) { return resource.readBytes() } else { diff --git a/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/Resource.desktop.kt b/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/Resource.desktop.kt index b6379f63e3..8aaf0ab74c 100644 --- a/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/Resource.desktop.kt +++ b/components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/Resource.desktop.kt @@ -13,7 +13,8 @@ actual fun resource(path: String): Resource = DesktopResourceImpl(path) @ExperimentalResourceApi private class DesktopResourceImpl(path: String) : AbstractResourceImpl(path) { override suspend fun readBytes(): ByteArray { - val resource = (::DesktopResourceImpl.javaClass.classLoader).getResourceAsStream(path) + val classLoader = Thread.currentThread().contextClassLoader ?: (::DesktopResourceImpl.javaClass.classLoader) + val resource = classLoader.getResourceAsStream(path) if (resource != null) { return resource.readBytes() } else {