From adt-21-preview DOC
Building
There\'s a new flag to force "jumbo mode" for dex which allows a larger number of strings
All strings constants are stored in a dex file in a single sorted list. The strings are then referenced elsewhere in the dex file by index within that list.
These string indexes are generally an unsigned 32-bit integer. As far as the actual instructions go, there are 2 instructions that can reference a string: const-string
and const-string/jumbo
. The first takes a 16-bit string index, and the second takes a 32-bit string index.
So, the maximum number of strings is 2^32 = 4294967296
To answer the OP's specific question:
private String foo = "fessy";
This would add two new entries to the string table, assuming no other class uses a variable called foo
, and the string "fessy"
does not appear anywhere else in your application.
If multiple independent classes use the same name for their variables/string literals, it only adds a single entry to the string table. This is one of the reasons to follow consistent naming conventions (ideally based on Android Framework code). Besides improving readability, it helps keeping the string count low.
You can easily check the string count by first extracting classes.dex from your apk file, and then dumping 4 bytes of the DEX header at offset 56 (see Dalvik Executable format):
$ jar xvf app.apk classes.dex && hexdump -s 56 -n 4 -e '1/4 "%d\n"' classes.dex
The maximum number of strings for a (non-jumbo mode) dex file is 2^16 = 65,536.