Reducing android app (apk) size

前端 未结 16 1367
借酒劲吻你
借酒劲吻你 2020-11-29 20:51

I would be now publishing my first app on Google play store. I have already compressed images used in my app. And I have some questions regarding the app size.

相关标签:
16条回答
  • 2020-11-29 20:51

    In most of the cases app size is propotional to the resource file(images and other stuff) that you use to create an application.Always consider the following.

    • Try using minimal images.(In most cases ,there is not need to add images in the Ldpi folder) .
    • Use vector images instead of putting images for all screen resolutions .One way is to use SVG ,9 patch
    • Try to use xml drawable to create generic images like square,rectangle circle,borders etc instead of .png images Try some image compression techniques.
    • Try fetching large images from Api rather than putting it in the res folder.(Download only when needed).

    Library imports

    • Try to remove unwanted libraries while creating a build for appstore.
    • If you need a particular functionality in a alibrary then try to extract the required class files and use it rather than importing the whole library jar.
    • Clean your class by removing unused import (although it won't have much effect on size but it will make things more simple and straight).In eclipe select the src folder->rightclick->source->organize imports
    0 讨论(0)
  • 2020-11-29 20:55

    For those of you doing much smaller projects, consider removing all the app-compat libraries. You may be better off making multiple versions of your app for specific versions of the API. I've seen a 47Kbyte app balloon to 3Mbytes just by adding compatibility libraries.

    Summary: to save space, avoid unnecessary libraries, even ones provided by Google (and included in most templates!).

    0 讨论(0)
  • 2020-11-29 20:59

    Check my blog Different ways to reduce apk size

    Main Points are :

    • android.enableR8=true // enable New R8 Code Shrinker
    • minifyEnabled true && Add Proguard Rules
    • Examine Your APK Using Android Studio’s APK Analyzer
    • Enable Resource Shrinking
    • Convert Your PNGs, JPEGs, and BMPs Into WebP
    • Avoid enumerations and use @IntDef annotation
    • Use aaptOptions { cruncherEnabled = false } to compress images
    • Use Remove Unused Resources android studio built-in function to remove all the unused resources in the application
    • Use Code Cleanup android studio built-in function to remove

    Note: Go enable it! (*just double and triple check everything works afterwards)

    0 讨论(0)
  • 2020-11-29 21:01

    It is one option that you compress all your PNGs for that you can go to https://tinypng.com/ .

    After that remove unnecessary library imports for example it is not require to import support library v4 if you already imported v7 for appcompat.

    And finally after completion of signing procedure of apk use zipalign tool that is shipped with android-sdk for more details refer http://developer.android.com/tools/help/zipalign.html.

    That's all i know.

    0 讨论(0)
  • 2020-11-29 21:03

    ProGuard by default applies its shrinking, optimization, and obfuscation -- that's its main purpose. You do have to enable it in your Android build, by editing the documented ProGuard line in your project.properties. It enables ProGuard (with or without optimization) for release builds with Ant and Eclipse. With Ant, you'll see ProGuard output in the build log.

    See the Android documentation > Tools > ProGuard.

    You should then check your processed application. You may need additional -keep options, e.g. possibly for Google Play Services. The less you can keep, the smaller your application will be.

    0 讨论(0)
  • 2020-11-29 21:05

    First of all look in to your drawables.

    1. If you are using a PSD to get the images for the app, those images might not be optimized for web and devices. You Photoshops "Save for Web and Devices" to optimize the images. You can reduce lot of kbs from this.
    2. Next, see if you can replace images with XML drawables. For example, buttons and background can be done using XML
    0 讨论(0)
提交回复
热议问题