mikepenz/Android-Iconics

Code too large error of IIcon enum

bismarabia opened this issue · 4 comments

About this issue

I have a custom ITypeface class with has an inner enum inside that extends IIcon interface.

The enum contains 2719 elements and it will contains more in the future.

Everything is fine; however, when I compile the project I'm getting this error

code too large error. (click to see the pic)

As far as I checked online, some says it's related to the byte codes allowed for each class as of 64K.

@mikepenz do you have any workaround to this? or can we user normal interface instead of enum? thanks.

We faced the exact same issue with the community material typeface. sadly this is a hard limitation of the java bytecode.

The way we worked around this was by having 2 enums instead:

https://github.com/mikepenz/Android-Iconics/blob/develop/community-material-typeface-library/src/main/java/com/mikepenz/iconics/typeface/library/community/material/CommunityMaterial.kt

with this you will then only be bound to the max byte size per class.

That being said. we were looking into other approaches of defining the fonts, but came to none which was serving the different requirements as good as an enum

Hmm, I see..

I think switching to interface (instead of enum) should completely solve the problem once for all.

any change later we make such a switch?

Also, what are the drawbacks (or inconveniences) of having interface rather than enum?

well we tried to have an interface. but the big problem is you won't have the possibility to iterate over it. you won't have direct static access via the definition.

if you want to bring back all those things you require to create a map with all objects, and have static mapping to get them. and this resulted in a bigger bytecode which we didn't want to move forward with

alright I see, thanks @mikepenz for elaborating...feel free to close the issue.