Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Difference in size between Build APK vs Run APK

I have noticed a difference in size between the apk generated with these 2 options.

why is this happening ?

With the Build -> Build APK option:

MyProject\app\build\outputs\apk\app-debug.apk (Size 2.997 KB)

With the Run app option:

MyProject\app\build\outputs\apk\app-debug.apk (Size 3.300 KB)

Thanks.

like image 623
seba123neo Avatar asked Jan 21 '16 13:01

seba123neo


2 Answers

Build APK is a shortcut for running the :app:assembleDebug Gradle task (assuming you have the debug variant active in the Build Variants window).

When running the application, we first ask you which device you want to target and then pass the information to Gradle. Among other things, this lets us filter out unnecessary resources. If you have Instant Run enabled, we also package additional code into the APK.

like image 99
Michał Bendowski Avatar answered Nov 16 '22 01:11

Michał Bendowski


When you create the build by Build->Build APK, the apk will contain all the resources for all the devices. i.e for ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi.

But in case you are running the app on device/emulator, it will detect that what the resolution of the phone is and will add only the resources with that resolution into the apk file. For ex, if your device is xhdpi , it will drop all other screen resolutions and will contain only xhdpi resources.

like image 24
Nishant Chauhan Avatar answered Nov 16 '22 03:11

Nishant Chauhan