Recently I have read about the Dalvik 65K method limit. I have understood that the method invocation list can only invoke first 65536 method references. To tackle this we have number of solutions. One of which being multidexing where we split the .dex files to number of classes [classes.dex, classes1.dex ...] by using android's support library.
What I have failed to understand is, what drawback does an android application suffer due to this multidexing and why should we put lots of effort in minimising the number of referenced methods.
Basically in my understanding, to reduce the method count I have to reduce modularisation, which makes my code bit less readable leaving apart the number of hours burned in striping down the codes of Third-party libraries. Is reducing the method count worth it??
Multidex support for Android 5.dex files and compiles them into a single . oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher multidex is enabled by default, and you do not need the multidex library. For more information on the Android 5.0 runtime, read ART and Dalvik.
Show activity on this post. You can disable multidex only if your project doesn't exceed either 65k methods limitation or 65k fields limitation. People seems to be unaware about the 65k fields limitation. You can hit the fields limitation if you're using huge total of resources like drawable, string id, etc.
You are overthinking about multidex, instead you should observe and identify if there is any performance issue with your app by profiling your application.
Multidexing hardly increases any size of code, major size and performance issues are with animation/image/audio/video resources, they are the ones who increase size and reduce performance.
Including many third party libraries will eventually pass 64k limit and almost all applications today are multidexed, Users demand multifeatured apps today, that requires integration with many third party libraries.
Only when you are doing animation/game programming, where speed matters the most, more method calls might be harmful, but this has nothing to do with multidexing, even poorly written small non multidexing app will perform bad on any device.
Startup time will affect with multidexing, but it can certainly be improved by changing your app logic to delay loading of other costly library and resources.
Is reducing the method count worth it??
NO
Ideally you should use more methods and modularize your code, because testing and changing mobile apps is huge challenge after it is published. Debugging and removing bugs are more costly then multidex size and its impact on performance. Due to tiny screens, different brands, different UI, users get more angry on apps on phone compared to computers. Keeping up to users demand will become easier if code is divided into multiple individual tested libraries.
The main drawback is a larger dex/apk size. Dex files have pools of constants that are shared among all the classes in that dex file. When classes are split across multiple dex files, these shared constants have to be duplicated in each dex file they are used in.
Multidexing itself is non-performing term, if application is multidex it means there is burden over android internal process which executes application.
Every android application runs inside a single process(task), when its multidexed, it means the process is divided into parts which going to create performance issues with small android processor, no matter how you write code.
I am agree with aakash kava that almost all applications are multidexed because now a days android processors are very good in performance and android RAM is excellent, But it does't ,mean we should ignore multidexing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With