Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What limits are there on the number of Android resources?

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?

like image 387
Ted Hopp Avatar asked Nov 21 '11 20:11

Ted Hopp


People also ask

What are the resources in an Android?

Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more. You should always externalize app resources such as images and strings from your code, so that you can maintain them independently.

What contains all the resources used to install an Android app?

It contains all the resources an app needs to run, including its Java code, native libraries, assets, manifest file, resource files, etc. The APK file format was created, so developers could deliver software to devices in a single compressed file. All the user-oriented programs on smart Android devices use APK files.

How do I manage resources in Android?

Accessing Resources When your Android application is compiled, a R class gets generated, which contains resource IDs for all the resources available in your res/ directory. You can use R class to access that resource using sub-directory and resource name or directly resource ID.

What is Android resource externalization?

Externalizing your resources also allows you to provide alternative resources that support specific device configurations such as different languages or screen sizes, which becomes increasingly important as more Android-powered devices become available with different configurations.


1 Answers

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.

like image 87
Ted Hopp Avatar answered Nov 15 '22 23:11

Ted Hopp