Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android APK Raw File Size vs Download Size. How to shrink the Raw File Size?

I'm using Android Studio 3.0. When I Analyze my APK, I see the following

Raw File Size: 4.1 MB, Download Size 3.3 MB.

Why is that different?

Since this is an Instant App, it prevents it from being uploaded. How could I shrink the Raw File Size without need to change my code/resource that is needed on download?

like image 637
Elye Avatar asked Jul 11 '17 03:07

Elye


People also ask

How do I reduce file size on Android?

Using an online PDF compressor. Open your browser and navigate to the Acrobat online PDF compressor. Tap on Select a File and locate your PDF on your Android device. Download your compressed PDF. You can also see how much the tool reduced the file size.

What is the difference between APK size and download size?

Raw File Size represents the unzipped size of the entity on disk while Download Size represents the estimated compressed size of the entity as it would be delivered by Google Play. The % of Total Download Size indicates the percentage of the APK's total download size the entity represents.

Can we compress APK file?

You can compress an APK file (rar, zip), but it has to be decompressed in order to work. ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions.


2 Answers

The APK Analyzer provides two sizes for each file which is packed into your APK, as well as overall for each 'directory', including total. These sizes do not indicate the compression that you got when the APK was created (APK format is ZIP compatible, so you can use unzip -lv qqq.apk to examine what effect this step had for squeezing the total).

For the end users, both sizes actually matter. With smaller Download Size, they get your app faster, and waste less off their data plan. With smaller Raw Size, the APK takes less space on the user's device.

But there are some tiny details to take into account. Let's take for example the native libraries (if your app uses NDK).

First of all, consider application update. Google Chrome team found that if they don't compress the native libraries, app updates become quite a bit smaller. If you multiply this gain by the number of expected app updates, this gives a major advantage.

Second, if you don't compress the native libraries, you can actually reduce the disk consumption of your app (for Android Marshmallow and above), because then, the libraries can be loaded in-place, without being unpacked to /data/data/your.app.package/lib.

Luckily, all this is managed by simply adding an attribute:

android:extractNativeLibs="false"

to the application tag in your AndroidManifest.xml file.

Same considerations may be applied to the assets: AssetManager can load them from inside the APK, without need to unpack them to disk - if the asset is not compressed in the APK.

APK Analyzer will show you how Google Play will squeeze such assets for download.

like image 56
Alex Cohn Avatar answered Oct 20 '22 02:10

Alex Cohn


From the documentation:

Raw File Size represents the unzipped size of the entity on disk while Download Size represents the estimated compressed size of the entity as it would be delivered by Google Play.

So the download size will almost always be smaller than the raw file size as Google Play does additional compression as it delivers the binary over the network.

There is no silver bullet to reduce raw file size, it's a matter of looking at where the space is being used within the APK and working out what you can remove. The docs have a fairly in depth guide to doing this.

like image 3
AdamK Avatar answered Oct 20 '22 03:10

AdamK