What limits are there on the number of Android resources?

拥有回忆 提交于 2019-12-03 11:10:47

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.

There's no explicit documentation on this that I know of either, however one can make reasonable assumptions that the Android devs have designed Android appropriately given their recommendations. They recommend that you put strings and drawables into resources with the potential to supply different ones for different locales, screen sizes, screen densities and orientations. The sheer number of these possibilities suggests to me that they expect apps to include thousands of resources and you'll be just fine supplying a few thousand small raw resources.

Taken into account the automatically class R and the resource value used in the api I would assume somewhere around Integer.MAX_INTEGER for string, drawable and layout id each.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!