The first start after installing or upgrading is definitely slower, mainly due to the expensive I/O operations required to extract the secondary dex files from the APK into the file system. Subsequent starts are also affected proportionally to the size and complexity of classes that have to be loaded in order to bring up your first Activity, so it's good to keep the main components of the app (specially activities) in the primary dex to minimize startup time, although it's not always possible to do so.我们已经看到,在Alcatel OneTouch(2.3.3)和Google Nexus One(2.3.6)手机中,由于dex提取而导致的ANR时间过长.在更现代的设备中,升级和冷启动Multidex应用程序可能会花费更长的时间,但通常不足以引起ANR.We've seen ANRs in Alcatel OneTouch (2.3.3) and Google Nexus One (2.3.6) phones that were caused by the dex extraction taking too long. In more modern devices, upgrading and cold starting multidex apps might take a bit longer but usually not long enough to cause ANRs.类加载变得非常慢,这以不可预测的方式影响应用程序.如果您使用DI系统,Protobuf或其他生成数百个类的框架,则可能会发现某些应用程序工作流启用multidex后,速度会降低20-25%.减轻这种情况的一种方法是通过例如后台线程或 BroadcastReceiver 提前加载类,但是这些当然会增加应用程序的内存占用并可能减慢设备速度Class loading becomes much slower and that affects the app in unpredictable ways. If you use a DI system, Protobuf or some other framework that generates hundreds of classes then you might find some of your application workflows becoming 20-25% slower after enabling multidex. One way to mitigate this is to load classes ahead of time via, for example, a background thread or a BroadcastReceiver but these, of course, will increate the memory footprint of the app and potentially slow down the device.此外,如果dexopts发现主dex中缺少的类,则也可能会跳过一些安装时dex优化,因此,即使只有几个类最终在次要dex上,也可能会在CPU和内存使用方面造成可观的损失.dex文件.Also, some install-time dex optimizations might also be skipped if dexopts finds classes missing from the primary dex, so there might be a considerable penalty in terms of CPU and memory usage even if only a couple of classes end up in secondary dex files. MultiDex解决了64K方法的局限性,但这不是灵丹妙药,不应将恕我直言作为借口,以避免优化APK的大小,但是如果MultiDex solves the 64K method limit but it's not a silver bullet and IMHO shouldn't be used as an excuse to avoid optimizing the size of the APK but if您只针对现代设备(例如API 16 +)性能/冷启动时间并不关键您没有时间进一步优化应用程序那么MultiDex可能是合适的,否则剥离不必要的代码是可行的方法.then MultiDex might be suitable, otherwise stripping unnecessary code is the way to go. 这篇关于使用Multidex对应用程序性能,稳定性,兼容性的影响...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!