Q:

Play compile in Android Studio result more optimized APK than `./gradlew app:assembleProductionRelease`

When I compile in Android Studio using the play button, i.e. it will Executing tasks: [:app:assembleProductionRelease], I got an APK with size that is smaller than when I run on command line ./gradlew app:assembleProductionRelease. 
Upon investigating the APK differences, apparently the more optimized APK striped away resource that is unused. 
I personally would think both ./gradlew app:assembleProductionRelease and Executing tasks: [:app:assembleProductionRelease] should behave the same. 
Given they are different, how could I investigate what is extra steps in Executing tasks: [:app:assembleProductionRelease] that help to optimize away the unused resources? 

A:

Found the reason. For the latest Android Studio, if you click play, it will ask for a particular device, and it will compile just to match that device. Hence the APK generated is more optimized. Try target two devices or more with vastly different API support level, you'll see your APK size grows.
Hence to release it, it's better to use the commandline ./gradlew assembleRelease to generate your APK.
Refers to https://medium.com/@elye.project/dont-publish-your-manually-compiled-apk-c8ce2bf7e6b4#.9uy2cdyry for more details.

