Our
apps are limited to a 64K method reference limit. If your app reaches
this limit, the build process outputs the following error
message:
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Tools
This
is a drap and drop tool which helps us to find the number of method
in apk http://inloop.github.io/apk-method-count/.
Which
helps us to be in safe-guard in optimizing things. Know we need some solutions to optimize the problem. Let find them
Solutions
MultiDex
MultiDex
allows you to use multiple DEX files contained within one APK. With a
few steps, your classes will split automatically into several DEX
files (classes.dex,classes2.dex,
classes3.dex,
etc) in case you reach the method index limit.
ProGuard
is
a tool that shrinks, optimizes and obfuscates your code by removing
unused code and renaming classes, fields and methods with
semantically obscure names.
JarJar
Jar
Jar Links
is
a utility that makes it easy to repackage Java libraries and embed
them into your own distribution.
Conclusion
At
this point, Google Play Services is perhaps the biggest common threat
on your methods count. I would love to see this API broken into
separate modules. A detailed
summary of this problem was
published a while ago by Jake Wharton & Android and the dex 64k methods limit by Tom Renzik, so feel free to dive into that
as well.
Another
interesting
blog post was published a while ago by Cyril Mottier,
illustrating how to reduce APK size using various different
techniques.
Thanks for reading :)
Whether this post is helpful?
Have something to add to this post? If you have any other quick thoughts/hints that you think people will find useful? Share it in the comments.