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

后端 未结 4 1839
我寻月下人不归
我寻月下人不归 2021-01-11 23:27

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

相关标签:
4条回答
  • 2021-01-11 23:56

    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.

    0 讨论(0)
  • 2021-01-12 00:05

    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

    0 讨论(0)
  • 2021-01-12 00:10

    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.

    0 讨论(0)
  • 2021-01-12 00:13

    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.

    0 讨论(0)
提交回复
热议问题