Have you ever had an Android build fail with the following message?
dex java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
It means that you have referenced too many methods. Apparently it’s a recent bug.
The sad thing about this error is that there’s really no way to figure out of all your dependencies, who the most egregious offenders are. That’s what I thought, until I discovered this tip.
Thanks to the amazing work by JesusFreke on this StackOverflow qustion, it is revealed that you can get the number of method references in a jar by first converting it to a dex file, and then reading the header.
Specifically, this is what I did to figure out the # of method references in my jars.
1. Grab all of the jar files
mkdir jars cp **/*.jar jars
2. Iterate through them, displaying the method size
for file in jars/*.jar; do echo $file; ~/android-sdk/build-tools/17.0.0/dx --dex --output=temp.dex $file 2> /dev/null cat temp.dex| head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"' done
(note that you should replace your android path as necessary)
3. Identify the highest count jars, remove them from your project
This is the hard part, but hopefully, you can find smaller libraries that do the same thing. The biggest offenders in my current project were Google guava (14265 methods), Jackson (8177 methods), and Google Play Services (5931 methods) – just a few libraries like these can easily add up and put you over the limit.