0

When I build big multi module project, result apk contains a lot of dex files. 35 on debug version and 15 on release. Most of files has far less methods and references then 65k.

Is there any way to compact dex files?

I also analysed several famous applications from google, instagram, and others. They all have 4-6 almost full dexes. Nothing like we have. So looks like compaction is possible

We also suspect that such big amount of dex files can slowdown application startup. Is it the case?

When I run application on android 4 device, I can literally see in logs how dex files getting unpacked. I didn't profile it, but looks like the speed is more or less the same for every file, may be i wrong here.

AGP 3.4, Gradle 5.5

on debug version: enter image description here

dex metrics on release version: enter image description here

Maksim Turaev
  • 4,115
  • 1
  • 29
  • 42
  • The first has the smallest because it has necessary methods for application startup. But I expect the dex sizes to be larger (~Mb) – Mahdi-Malv Sep 04 '19 at 14:02
  • It won't slow down the app startup, that depends on your code, if its intensive then it will. – Darshan Sep 04 '19 at 14:06
  • @Mahdi-Malv actually, first dex is among top 5 largest. It has 2mb and 50k+ reference methods. We even has to manualy decrease amount of classes in it, to fix MainDexLimit exception – Maksim Turaev Sep 04 '19 at 14:10
  • @DarShan but when I run application on android 4 device I can literally see in logs how dex files getting unpacked. I didn't profile it, but looks like the speed is more or less the same for every file – Maksim Turaev Sep 04 '19 at 14:12
  • 1
    Is that from a debug or release build? You might try a release build - I think it may do more work to pack the classes into as few dex files as possible. – JesusFreke Sep 04 '19 at 18:02
  • @JesusFreke thanks for suggestion. On release build there is only 15 dexes, on debug it was 35. But there are still a lot of dexes that are not compacted. Looks like it is just, result of proguard work. It seams there are two groups of dexes, six dexes: average Classes/Methods/MethodRefs = 8500/50000/61300 and 9 others 1700/8400/11600 – Maksim Turaev Sep 05 '19 at 07:19
  • @JesusFreke exact numbers rounded by 100 here https://imgur.com/0TAFNjq – Maksim Turaev Sep 05 '19 at 07:28
  • 1
    @MaksimTuraev Interesting. Just curious if you were able to identify the time where it started to happen.. I mean - does your app always had such large amount of dex files? Maybe upgrading to a particular AGP version triggered this behavior? – Alex Lipov Sep 09 '19 at 05:57
  • @MaksimTuraev What is the `minSdkVersion` of your app? – Alex Lipov Oct 13 '19 at 07:42
  • 1
    @AlexLipov min sdk is 16. I suspect that the problem is probably related to modifications to the MainDexList we do to overcome MainDexLimit – Maksim Turaev Oct 13 '19 at 08:59

0 Answers0