Android 资源数量有什么限制?
我们的一个应用程序有数千个小数据文件,我们目前将其打包为资产。如果我们可以将它们打包为原始资源,这将对我们的代码有所帮助。我试图找出应用程序可以拥有的每种类型的资源数量的限制,但我没有找到任何相关文档。有谁知道Android资源数量的限制是什么?
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 to track down what the limits are for the number of resources an app can have of each type, but I haven't found any documentation on this. Does anyone know what the limits are on the number of Android resources?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经过大量实验后,似乎每种资源类型最多可以拥有 16 位资源(65,536 个资源)。 (可能会保留额外的位供将来使用,这会减少最大资源计数,但我找不到任何证据。)如果有人可以提供权威答案,那就太好了,但一年后,我'我放弃了。
编辑(请参阅下面@@的评论B T):基于hackbod 在另一个线程中的回答,似乎确实有 16 位可用,因此最多可以拥有 65,535 个资源任何一种类型(不是 65,536,因为零不可用)。另请注意,此限制仅适用于单个配置(区域设置、像素密度等)的资源数量。不同配置的资源变体共享相同的资源 ID,并且不参与计数。因此,您实际上可以拥有超过 65,535 个任何一种类型(例如,布局或字符串)的资源,但不适合任何一种配置。
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.
据我所知,也没有关于这方面的明确文档,但是人们可以做出合理的假设,即 Android 开发人员已经根据他们的建议适当地设计了 Android。他们建议您将字符串和绘图放入资源中,以便为不同的区域设置、屏幕尺寸、屏幕密度和方向提供不同的字符串和绘图。这些可能性的绝对数量表明,他们希望应用程序包含数千个资源,而您提供几千个小型原始资源就可以了。
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.
考虑到自动类 R 和 api 中使用的资源值,我会假设字符串、可绘制对象和布局 id 都在 Integer.MAX_INTEGER 附近。
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.