Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce size of an apk file? [duplicate]

First of all, don't suggest me official documentation or this. When we build an app from Android Studio with predefined textview that simply displays "hello world", it generates an APK with more than 1.2MB. But some apps on playstore is available under 500KB with lot of features. I already applied all features of Android Studio like proguard, minifyEnabled etc. but that does not help. So, how can i achieve that level of compression?

like image 386
Rohit Singh Avatar asked Feb 06 '18 08:02

Rohit Singh


People also ask

Can you compress APK files?

You can compress an APK file (rar, zip), but it has to be decompressed in order to work. ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions.

What is an average size of an APK?

Average Android and iOS file size Of all mobile apps published on the app stores, the average Android app file size is 11.5MB. And the average iOS app file size is 34.3MB.


2 Answers

When create new project from Android studio, the IDE automatically add some dependencies to your project.

dependencies {
    // ...
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    // implementation 'com.android.support:appcompat-v7:26.1.0'
    // implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    // ...
}

If you bundle support library and constraint layout library, your release apk size will increase rapidly even you don't add any code.

You can get a very small apk if you remove support library and constraint layout library and just use all the system api.

After remove the support library, you should

  1. use Activity rather than AppCompatActivity, YourActivity extends Activity

  2. do not use any theme from support library in your AndroidManifest.xml

  3. use FrameLayout to replace ConstraintLayout in your layout

like image 133
alijandro Avatar answered Sep 19 '22 09:09

alijandro


Points to reduce APK size:
1. Use vector drawable
2. Use xml drawable to create simple view
3. Rotate images using xml drawable to reuse (eg. in case of arrow buttons)
4. Create drawable through code
5. Use aaptOptions { cruncherEnabled = false } to compress images
6. Use webP format for large images
7. Avoid enumerations and use @IntDef annotation
8. Use shrinkResources true in gradle to remove unused resources
9. Use resConfig “en” in gradle to remove other localization

like image 34
Sanjay Kumar Avatar answered Sep 21 '22 09:09

Sanjay Kumar