How to reduce apk size when using play services gcm

前端 未结 3 729
故里飘歌
故里飘歌 2021-01-22 01:23

My generated signed apk size is 30kB, when I add play services gcm to gradle file the apk size increased to 800kB. by shrinking resource the apk size become 600

相关标签:
3条回答
  • 2021-01-22 01:40

    At the moment that is the size of that dependency. The reason that the .apk gets an increase in size for every dependency is because your application requires those to function, and cannot depend on accessing it from a remote location, incase a device does not have an internet connection.

    According to this, (and IntelliJ's comment), if you configure your proguard you can try to reduce the size a little.

    Also consider the following: Shrink Google Play Services library for use with Google Analytics only.

    0 讨论(0)
  • 2021-01-22 01:40

    Looking at your build.gradle, you have already taken of Source code and resource optimization. The things you are missing is:

    1. Removing unused configuration with ResConfigs

      Many libraries like support/Google play services comes with string resources translate in too many languages. You might not be intending to support all of them. Using following way, you can control the size:

      android {

      defaultConfig {
          ...
          resConfigs "en"
      }}
      

      This will remove all the resources that are not meant for English.

    2. Sparse Configurations

      This is usually applicable for applications with large number of strings. In case of some features, you might be tempted to create strings under values-22/strings.xml. The problem with this approach is reserves space for pointers on every possible resource position. So even though the string is not present in new file, it still take space for pointer which is around 4 bytes of null data. You can use tool named ArscBlamer from Google to locate this sparse configurations.

    3. Image Optimization

      You can perform some image optimizations using WebP and Zopfli-compressed PNGs. You have to carefully weigh the downsides of using them. The details are available here

    More details on these approaches is available here

    0 讨论(0)
  • 2021-01-22 01:49

    from http://proguard.sourceforge.net/manual/examples.html#application

    -optimizationpasses 3

    -overloadaggressively

    -repackageclasses ''

    -allowaccessmodification

    these might help. (in particular the 3 passses)

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