What limits are there on the number of Android resources?

后端 未结 3 1666
一生所求
一生所求 2021-02-13 22:00

One of our apps has several thousand small data files that we\'re currently packaging as assets. It would help our code if we could package them as raw resources. I have tried t

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-13 22:42

    After a lot of experimenting, it seems that you can have up to 16 bits worth of resources (65,536 resources) for each resource type. (There may be additional bits reserved for future use, which would reduce the max resource count, but I couldn't find any evidence of this.) It would be nice if someone could provide an authoritative answer, but after a year, I'm giving up.

    EDIT (see the comment below by @B T): Based on this answer by hackbod in another thread, It seems that there are, indeed, 16 bits available, so one can have up to 65,535 resources of any one type (not 65,536, because zero is not available). Also, note that this limit applies only to the number of resources for a single configuration (locale, pixel density, etc.). Variations of a resource for different configurations share the same resource ID and don't contribute to the count. So you can actually have a lot more than 65,535 resources of any one type (e.g., layout or string), just not for any one configuration.

提交回复
热议问题