moko-resources
moko-resources copied to clipboard
ResourceContainer.getImageByFileName extension is not compatible with isMinifyEnabled = true on Android
ResourceContainer.getImageByFileName(fileName: String) cannot find image by name when isMinifyEnabled = true in build.gradle.
The function works fine when the source code is not changed (when isMinifyEnabled = false).
However, when isMinifyEnabled = true, the names of variables in the MR class are changed and getImageByFileName(fileName) returns null.
Thanks for report! Maybe you have ideas how it can be fixed?
Here's my workaround:
fun getImageByFileName(fileName: String) = ImageResource(
context.resources.getIdentifier(
fileName.toLowerCase(Locale.getDefault()),
"drawable",
context.packageName
)
)
And it works when isMinifyEnabled = true. But this is not an extension from ResourceContainer and my function requires a Context
Можно добавить правило для R8/proguard
-keep class packageName.MR$images { *; }