iroyo iroyo - 5 months ago 11x
Android Question

Huge Apk difference between gradle v1.x vs v2.x

The other day I was inspecting "App Info" from an app I'm developing and to my surprise I detected an enormous amount of Mb were being used as "cache" (the app didn't download any content yet, it was just a mockup). At first I thought I could be some heavy libraries I'd added (fresco..) so I decided to create a blank project an try to figure out what was the problem.

I've tried 2 scenarios: pre-lollipop and lollipop. With this I found out there is some difference with the way they handle "data" but the overall apk size was the same. Though here, in pre-lollipop (4.4.4) there was almost no "cache"(FIRST IMAGE) in lollipop... well 8 mb of "cache".

lollipop vs pre-lollipop - gradle 2.1

All of this wasn't enough since the other apps I'd developed in lollipop and above had way less "cache". I started thinking what could be the difference and finally I think I've found somthing, gradle version!

lollipop vs pre-lollipop - gradle 1.5

The project build with gradle 1.5 has smaller apk size and almost no "cache" (both lollipop and pre-lollipop)

Is there something I'm missing? Why the sudden increase in "cache" size.

Is there any way to avoid this while using the latest gradle version?


Instant Run ships incremental chunks of your app, reflecting changes that you made to the code. That stuff still needs to be loadable by your app, so they apparently are putting that information in some location that gets counted as "cache" (getCacheDir()?).

Similarly, your app's main APK itself will be a bit larger, as it has to contain a chunk of code that knows how to load these dynamically-changing bits.

If you need to measure these values, either disable Instant Run, or run a release build (which automatically is non-Instant Run).