You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Launch the application with the sharedUserId attribute in the Manifest.xml.
Expected behavior
The app is able to load resources regardless of whether it uses a sharedUserId or not
Screenshots
N/A
Additional context
I maintain an application that has unfortunately inherited a sharedUserId. My team has been building out a replacement app using Compose Mutliplatform, and we recently added in the sharedUserId to prepare it for submission to the Play Store. The addition of the sharedUserId prevents the app from loading any images or strings (fonts load fine because the underlying implementation delegates to Android's asset loader).
I investigated the issue and narrowed it down to the class loader. Removing Thread.currentThread().contextClassLoader from ResourceReader.android.kt seemed to fix the issue for me:
// Before (crashes)
private fun getClassLoader(): ClassLoader {
return Thread.currentThread().contextClassLoader ?: this.javaClass.classLoader!!
}
// After (runs)
private object ResourceReader
private fun getClassLoader(): ClassLoader {
return ResourceReader.javaClass.classLoader!!
}
I know essentially nothing about class loaders, so I don't know the implications of just removing the Thread's context class loader here. Hopefully the above hack at least demonstrates what's causing the issue 😅
The text was updated successfully, but these errors were encountered:
@terrakok, it is reproduced on the provided project. sharedUserId is deprecated, but it isn't possible to migrate old projects that needs to be maintained. Can we use the suggested fix?
…argets (#4895)
The class loader retrieval method has been modified in both
`ResourceReader.android.kt` and `ResourceReader.desktop.kt` files. The
return statement has been changed to prioritize java class classLoader
and provides a clearer error message when it can't be found.
Fixes#4887Fixes#4742
## Release Notes
### Fixes - Resources
- Delete contextClassLoader usage on JVM targets
Describe the bug
Compose Resources fails to load resources on Android when the application is using a
sharedUserId
Affected platforms
Versions
To Reproduce
Minimal reproducer using
kmp.jetbrains.com
's Android template:https://github.com/garrison-henkle/composeResourcesSharedUserIdBug
Stacktrace is also in the above repo's
README.md
Steps:
sharedUserId
attribute in theManifest.xml
.Expected behavior
The app is able to load resources regardless of whether it uses a
sharedUserId
or notScreenshots
N/A
Additional context
I maintain an application that has unfortunately inherited a
sharedUserId
. My team has been building out a replacement app using Compose Mutliplatform, and we recently added in thesharedUserId
to prepare it for submission to the Play Store. The addition of thesharedUserId
prevents the app from loading any images or strings (fonts load fine because the underlying implementation delegates to Android's asset loader).I investigated the issue and narrowed it down to the class loader. Removing
Thread.currentThread().contextClassLoader
from ResourceReader.android.kt seemed to fix the issue for me:I know essentially nothing about class loaders, so I don't know the implications of just removing the
Thread
's context class loader here. Hopefully the above hack at least demonstrates what's causing the issue 😅The text was updated successfully, but these errors were encountered: