Company
Date Published
Author
Tom Reznik
Word count
1307
Language
English
Hacker News points
None

Summary

The 64K method reference limit in Android is imposed by the current set of Dalvik instructions, specifically invoke-* methods that expect a 16-bit argument for the target method's reference index, limiting valid values to between 0 and 65536. This can be reached by including popular third-party libraries such as Google Play Services, Guava, AppCompat V7, Android Support V4, Jackson, Joda-Time, Apache Commons Lang3, Apache Commons IO, Gson, and others. To avoid this limit, developers can use ProGuard to strip out unnecessary class references or load secondary dex files at runtime using the DexClassLoader. Alternatively, MultiDex allows splitting classes into multiple dex files, enabling a 64K method reference limit without exceeding it. By adding the --multi-dex flag to the build.gradle file and utilizing the Android Support Library's MultiDex support, developers can overcome the 64K method reference limit. ProGuard can also be used to shrink, optimize, and obfuscate code by removing unused code and renaming classes, fields, and methods with semantically obscure names.