Search code examples
androidapk

After adding large png images .SO created leading to increase in app size


I replaced some png images in my project and the app bundle did not build successfully as the png files were too large each 2-3mb. I then changed the images with some jpegs which were a few hundred kb in size per file. After that when I built the app the size of the app went from 9mb to 27 mb. I analyzed the apk and most of the size is due to some lib files

apk analysis

I deleted the build folder to remove any old files but it did not help.I excluded all .so files but the apk is not installing without them. I tried making a bundle but that is also the same size. What should I do to revert back to the old apk size.


Solution

  • Read Add multi-density vector graphics

    Android Studio includes a tool called Vector Asset Studio that helps you add material icons and import Scalable Vector Graphic (SVG) and Adobe Photoshop Document (PSD) files into your project as vector drawable resources. Using vector drawables instead of bitmaps reduces the size of your APK because the same file can be resized for different screen densities without loss of image quality.

    You should use SVG images instead of JPG/PNG.

    To make your app as small as possible, you should enable shrinking in your release build to remove unused code and resources. When enabling shrinking, you also benefit from obfuscation, which shortens the names of your app’s classes and members, and optimization, which applies more aggressive strategies to further reduce the size of your app.

    Read Shrink, obfuscate, and optimize your app

      android {
        buildTypes {
            release {
                // Enables code shrinking, obfuscation, and optimization for only
                // your project's release build type.
                minifyEnabled true
    
                // Enables resource shrinking, which is performed by the
                // Android Gradle plugin.
                shrinkResources true
    
                // Includes the default ProGuard rules files that are packaged with
                // the Android Gradle plugin. To learn more, go to the section about
                // R8 configuration files.
                proguardFiles getDefaultProguardFile(
                        'proguard-android-optimize.txt'),
                        'proguard-rules.pro'
            }
        }
    
    }