moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

ResourceContainer.getImageByFileName extension is not compatible with isMinifyEnabled = true on Android

Open epicarchitect opened this issue 4 years ago • 3 comments

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.

epicarchitect avatar Jun 16 '21 07:06 epicarchitect

Thanks for report! Maybe you have ideas how it can be fixed?

Alex009 avatar Jun 16 '21 07:06 Alex009

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

epicarchitect avatar Jun 16 '21 07:06 epicarchitect

Можно добавить правило для R8/proguard -keep class packageName.MR$images { *; }

ShirobokovNE avatar Jun 15 '22 10:06 ShirobokovNE