3

I recently noticed that a lot of dex files (totaling over 40 MBs of data) are being stored in my app's cache directory. I find this unusual since a quick search shows that dex files should be stored in the /data/dalvik-cache directory and not the general app cache directory.

I wanted to know why this is since:

  1. It is taking up a lot of space in my app's cache directory.
  2. My app sometimes needs to clear the cache directory and when it does so, the time it takes the app to startup again is increased drastically (10-20 seconds). Presumably because Android needs to recreate these dex files.

Thank you in advance!

Update

My device is running Android 6.0.1. Here is an excerpt of my app's cache directory:

drwx------ u0_a178  u0_a178           2016-08-07 22:56 okhttp
drwx------ u0_a178  u0_a178           2016-08-07 23:08 org.chromium.android_webview
-rw-r--r-- u0_a178  u0_a178   1919104 2016-08-07 22:56 slice-MPAndroidChart-v2.2.4_756cc00da936eb4e219a44a244b55e2df68d07e2-classes.dex
-rw-r--r-- u0_a178  u0_a178     74664 2016-08-07 22:56 slice-com.android.support-animated-vector-drawable-24.1.1_0eb7fa04565008cb6cbb1feab2ae0affa5250da4-classes.dex
-rw-r--r-- u0_a178  u0_a178   2865992 2016-08-07 22:56 slice-com.android.support-appcompat-v7-24.1.1_ade323d4e3df1f7773864c565dd60eea04590c76-classes.dex
-rw-r--r-- u0_a178  u0_a178    129848 2016-08-07 22:56 slice-com.android.support-cardview-v7-24.1.1_5a2590aaa21e69d85533742fbf35c4a80037594f-classes.dex
-rw-r--r-- u0_a178  u0_a178   1266992 2016-08-07 22:56 slice-com.android.support-design-24.1.1_bae3a91de6040c93aed67ba25c118a1eb2cd63d0-classes.dex
-rw-r--r-- u0_a178  u0_a178     67576 2016-08-07 22:56 slice-com.android.support-percent-24.1.1_eef44a28578a5bdac3ec7f4f8fe6db395b9242f5-classes.dex
-rw-r--r-- u0_a178  u0_a178   1642120 2016-08-07 22:56 slice-com.android.support-recyclerview-v7-24.1.1_07c9cf9bb8d7da6bdbc7c7ce0e107b56362aa6e1-classes.dex
-rw-r--r-- u0_a178  u0_a178   5368720 2016-08-07 22:56 slice-com.android.support-support-v4-24.1.1_3f84799af1c5ce5634d5302937609addc3d526de-classes.dex
-rw-r--r-- u0_a178  u0_a178    245256 2016-08-07 22:56 slice-com.android.support-support-vector-drawable-24.1.1_183c04613849d18c534c9c96e5b5186bdf542d11-classes.dex
-rw-r--r-- u0_a178  u0_a178    234976 2016-08-07 22:56 slice-com.crashlytics.sdk.android-answers-1.3.7_7d587ccfdb8d98904ff3416a950d4ca3d718fc04-classes.dex
-rw-r--r-- u0_a178  u0_a178     76296 2016-08-07 22:56 slice-com.crashlytics.sdk.android-beta-1.1.5_2fa53876dc0fc447f8152c075ab46f0d8d92a816-classes.dex
-rw-r--r-- u0_a178  u0_a178     45904 2016-08-07 22:56 slice-com.crashlytics.sdk.android-crashlytics-2.5.6_fb76c5554f0f0d4fc0a08ade7b64b0268ce17199-classes.dex
-rw-r--r-- u0_a178  u0_a178    612144 2016-08-07 22:56 slice-com.crashlytics.sdk.android-crashlytics-core-2.3.9_2dff6f00a6ff1f48d87225bdaeac3553925a96a1-classes.dex
-rw-r--r-- u0_a178  u0_a178   3565568 2016-08-07 22:56 slice-com.google.android.gms-play-services-ads-9.2.1_287b02684d9f21d460a20b44d7850ec566e57278-classes.dex
-rw-r--r-- u0_a178  u0_a178   1664224 2016-08-07 22:56 slice-com.google.android.gms-play-services-ads-lite-9.2.1_ded75934ccfef925c6aa74ca2000dbc6904d5258-classes.dex
-rw-r--r-- u0_a178  u0_a178   1233032 2016-08-07 22:56 slice-com.google.android.gms-play-services-base-9.2.1_359213862239d71bf62ed09377d593890ed8403c-classes.dex
-rw-r--r-- u0_a178  u0_a178   3085656 2016-08-07 22:56 slice-com.google.android.gms-play-services-basement-9.2.1_70ce5ca57eb75287bd07834797967b46576d6fb7-classes.dex
-rw-r--r-- u0_a178  u0_a178    223936 2016-08-07 22:56 slice-com.google.android.gms-play-services-clearcut-9.2.1_6c6330c827462491a41455b4ed9262ce276082a9-classes.dex
-rw-r--r-- u0_a178  u0_a178     50472 2016-08-07 22:56 slice-com.google.android.gms-play-services-gass-9.2.1_1d2be8e71249040cb385274d0b324ea16d3879ec-classes.dex
-rw-r--r-- u0_a178  u0_a178    102832 2016-08-07 22:56 slice-com.google.android.gms-play-services-tasks-9.2.1_922d581385edc6689dc58268229f0677eaa652ec-classes.dex
-rw-r--r-- u0_a178  u0_a178    122848 2016-08-07 22:56 slice-disklrucache-2.0.2_a161adf664669683c31953160e5205319f8b5cd4-classes.dex
-rw-r--r-- u0_a178  u0_a178    904856 2016-08-07 22:56 slice-gson-2.4_a6797fe63a0f01937ca151851d4933eb1f53d03b-classes.dex
-rw-r--r-- u0_a178  u0_a178   1418992 2016-08-07 22:56 slice-internal_impl-24.1.1_1aa620cefcfc678e4b33946a0285c30664a7bc02-classes.dex
-rw-r--r-- u0_a178  u0_a178   1018112 2016-08-07 22:56 slice-io.fabric.sdk.android-fabric-1.3.11_37c4b03d2dd42835d17319c32054c93008baf362-classes.dex
-rw-r--r-- u0_a178  u0_a178   1405656 2016-08-07 22:56 slice-jsoup-1.9.2_5418f1f89f6018c691a8c003aa26c56de67bd7af-classes.dex
-rw-r--r-- u0_a178  u0_a178   1557672 2016-08-07 22:56 slice-okhttp-3.3.0_3ce69bdb19c526170b282b56e8a73f9c77c74b9a-classes.dex
-rw-r--r-- u0_a178  u0_a178    425616 2016-08-07 22:56 slice-okio-1.8.0_81dd90ec651c4bc7aa252b97e6338a5a365dcfb1-classes.dex
-rw-r--r-- u0_a178  u0_a178     99104 2016-08-07 22:56 slice-org.apmem.tools-layouts-1.10_495a455557b5a529e5dfebcdc6a3bc57243903cb-classes.dex
-rw-r--r-- u0_a178  u0_a178    186216 2016-08-07 22:56 slice-slice_0-classes.dex
-rw-r--r-- u0_a178  u0_a178     28200 2016-08-07 22:56 slice-slice_1-classes.dex
-rw-r--r-- u0_a178  u0_a178    541768 2016-08-07 22:56 slice-slice_2-classes.dex
-rw-r--r-- u0_a178  u0_a178      8872 2016-08-07 22:56 slice-slice_3-classes.dex
-rw-r--r-- u0_a178  u0_a178   1954440 2016-08-07 22:56 slice-slice_4-classes.dex
-rw-r--r-- u0_a178  u0_a178   7168784 2016-08-07 23:08 slice-slice_5-classes.dex
-rw-r--r-- u0_a178  u0_a178      8872 2016-08-07 22:56 slice-slice_6-classes.dex
-rw-r--r-- u0_a178  u0_a178   3348288 2016-08-07 22:56 slice-slice_7-classes.dex
-rw-r--r-- u0_a178  u0_a178    601304 2016-08-07 22:56 slice-slice_8-classes.dex
-rw-r--r-- u0_a178  u0_a178     35224 2016-08-07 22:56 slice-slice_9-classes.dex
-rw-r--r-- u0_a178  u0_a178     17064 2016-08-07 22:56 slice-support-annotations-24.1.1_b529bf0c82ba4e707c1b9be345d7c92d60cd7e8d-classes.dex
Community
  • 1
  • 1
idunnololz
  • 8,058
  • 5
  • 30
  • 46
  • are you using phone with OS version > 5.0 ? – jitinsharma Aug 08 '16 at 06:42
  • Yes. My phone is running version 6.0.1. – idunnololz Aug 08 '16 at 06:43
  • From what i know, the ART does a lot of pre-compiling when app is installed. This increase app's data size. One more point, dalvik-cache cannot be deleted programatically(as it is present in root directory) so .dex are not being deleted. Your app level cache resides somewhere else which is being deleted everytime you clear cache. – jitinsharma Aug 08 '16 at 06:45
  • @jitinsharma yes this is true and expected. However this data should not be stored in the cache directory. Also, other apps does not seem to have this problem so I find this very odd. – idunnololz Aug 08 '16 at 06:46
  • When your app is launched first time, android will automatically cache a "few things" so that next launch is always fast. These can be deleted by clearing cache which is present at `/data/data/com.my.appName/cache` dalvik-cache is completely different thing. – jitinsharma Aug 08 '16 at 06:49
  • What I am concerned about is why other app's cache size seem to hover around 2MB or less and my app's cache size is filled with 40MB of dex files. This seems extremely abnormal. I'm wondering if there is something wrong with my app. – idunnololz Aug 08 '16 at 06:51
  • .dex count increase could be due to number of libraries you are using. Each library will increase function count as well as size. Try using proguard to shrink resources. – jitinsharma Aug 08 '16 at 06:57
  • Actually,I have the 100% same question with you. They doesn't understand your question and the answer is far away. The problem cause it may be we use the MultiDex.install(this); in our Application.So that it create lots of dex files in your cachedir. My solution is using the ExternalCacheDir to store cahce but not CacheDir.And if you want user to clear cache in your Application, do not clear the path of CacheDir instead of the ExternalCacheDir,So that it will not delete the application dex and next time you open the appliction again you will not wait .(10-20 seconds) – hugoFather Jun 30 '17 at 05:19

1 Answers1

1

It's because of Instant Run, when you build release apk, you won't see that this cache dir is so big, it will be normal and won't contain all these dex files.

alla
  • 529
  • 5
  • 20