I have noticed a difference in size between the apk generated with these 2 options.
why is this happening ?
With the Build -> Build APK opti
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
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.
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.