简体   繁体   中英

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.

When you create the build by Build->Build APK, the apk will contain all the resources for all the devices. ie 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.

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.

My instant run was off.

I got 6MB APK size using Run->Run 'App' and 11MB using Build->Build APK option for both signed and unsigned APK. Build->Generate Signed APK... option also gives me 11MB APK for my app.

I think Android Studio drop some resources to make build faster.

APK with 11MB size have more resources so it will be better option to upload on play-store.

I used Build->Analyze Apk... to analyse both APK's so I found 5.7mb difference in res cause by some extra drawables from v4 and v17 libraries.

在此输入图像描述

This would probably be better answered if posed as an issue to the Android Studio team. My guess is that you're using Instant Run inside Android Studio (AS). This would explain the larger size since Instant Run generates proxy classes for changed code.

Edit the Run configuration to build using gradle build and you should be able to remove the extra code... But this WILL come with a much larger build/deploy time... If size of a debug build is really important to you then OK but for most this will ruin all the improvements the Android team has made to the DSL recently to improve speed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM