1

enter image description here

I have read various approach to reduce the APK size, I have applied ProGaurd and minify enabled - true, shrinkResources-true etc... but the issue is Google gsm folder is taking most of the APK size, I need GCM, Analytics, auth, and ads. I have added dependency separately for each requirement. Please tell me more to reduce this GSM folder size. will be a great help.

Nick Felker
  • 11,536
  • 1
  • 21
  • 35
Peter
  • 1,069
  • 2
  • 13
  • 24
  • 1
    Try to generate release APK and check if you still get same size APK. – Sanjay Sharma Nov 12 '18 at 07:41
  • @snj yes it did reduce to 1 more MB down but I think it because of some optimization going in backend during Release build! my actual code is of 1.4 MB and rest all is occupied by libraries. is there any way to find the library size – Peter Nov 13 '18 at 06:58
  • I cannot write all ways to reduce APK size in comment so I have posted in answer to reduce APK size. Check if any of them works for you. You can also check [this](https://stackoverflow.com/a/22674446/4788260) answer. – Sanjay Sharma Nov 13 '18 at 14:58
  • would like to share my presentation on "Reducing apk size" https://speakerdeck.com/pareshmayani/generating-efficient-apk-by-reducing-size-and-improving-performance – Paresh Mayani Nov 13 '18 at 15:02

1 Answers1

0

Firstly android libraries dependent code cannot be removed as part of optimizing the size of APK. Still you can use following ways to reduce APK size:

  1. Try to use proguard-android-optimize.txt instead of proguard-android.txt. It can reduce some more KBs of APK size depending on the libraries used in your project (worked for me).

    release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), "proguard-rules.pro"
            //Other useful parameters
            debuggable false
            jniDebuggable false
            renderscriptDebuggable false
            pseudoLocalesEnabled false
            zipAlignEnabled true
        } 
  2. Reduce resources using following

    release {
            ...
            shrinkResources true
            ...
        } 
  3. Remove localized resources if any library has that

    defaultConfig {
               ...
               resConfigs "en", "fr"
               ...
         }
  4. Try to use 9 patch image if possible. Use this method

  5. Use vector drawable wherever possible
  6. Convert images in WebP
  7. Try to reduce large PNG image size or use this site
  8. Add libraries specific to particular flavor of app only. For e.g. use Ads library for free flavor only. See this     
    dependencies {
            freeImplementation 'com.google.firebase:firebase-ads:9.8.0'
        }
  9. Add dynamic feature modules to your app. These modules contain features and assets that you can decide not to include when users first download and install your app. Check this
  10. Try to troubleshoot resource shrinking as given here
Sanjay Sharma
  • 3,687
  • 2
  • 22
  • 38