How to Reduce App (.Apk) Size

How to reduce Apk (.apk) size in android studio

I solve this issue by adding this code in module app build.gradle file.

 android {
packagingOptions{
exclude 'AndroidManifest.xml'
exclude 'lib/arm64-v8a/libcardioDecider.so'
exclude 'lib/arm64-v8a/libcardioRecognizer.so'
exclude 'lib/arm64-v8a/libcardioRecognizer_tegra2.so'
exclude 'lib/arm64-v8a/libopencv_core.so'
exclude 'lib/arm64-v8a/libopencv_imgproc.so'
exclude 'lib/armeabi/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer_tegra2.so'
exclude 'lib/armeabi-v7a/libopencv_core.so'
exclude 'lib/armeabi-v7a/libopencv_imgproc.so'
exclude 'lib/mips/libcardioDecider.so'
exclude 'lib/x86/libcardioDecider.so'
exclude 'lib/x86/libcardioRecognizer.so'
exclude 'lib/x86/libcardioRecognizer_tegra2.so'
exclude 'lib/x86/libopencv_core.so'
exclude 'lib/x86/libopencv_imgproc.so'
exclude 'lib/x86_64/libcardioDecider.so'
exclude 'lib/x86_64/libcardioRecognizer.so'
exclude 'lib/x86_64/libcardioRecognizer_tegra2.so'
exclude 'lib/x86_64/libopencv_core.so'
exclude 'lib/x86_64/libopencv_imgproc.so'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.paypal.sdk:paypal-android-sdk:2.14.1'
}

How to reduce App (.apk) Size

I would recommend that you compress the .jpg files as much as possible, this should greatly reduce the size of your .apk file. A tool such as Paint.NET which is free should help you do this. It has great resizing options.

How to reduce size of an apk file?

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

Android App apk size vs. install size and how to decrease them?

I use this method to decrease the apk size, you need to go to the build.gradle file and find a line that looks like that:

minifyEnabled false;

Change it to "true".

Add this line of code under:

shrinkResources = true

If you want to know more about this, see this Android Studio link: https://developer.android.com/studio/build/shrink-code

Also, to reduce more the apk size, upload your application as apk bundle to the play store, this will compress more the app.



Related Topics



Leave a reply



Submit