Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IONIC Android Apk File size Way Too Big ! how to decrease the size of app for android?

I created the app using Ionic and the Android APK file size is too big.

Before the API integration The File Size was 4.8MB. When I integrated the API I modified just 10 Pages now the APK file size is 71 MB.

Here are the Cordova Plugins I have used:

  • cordova-plugin-console
  • cordova-plugin-datepicker
  • cordova-plugin-device
  • cordova-plugin-network-information
  • cordova-plugin-splashscreen
  • cordova-plugin-statusbar
  • cordova-plugin-whitelist
  • cordova-plugin-x-socialsharing
  • cordova-sqlite-storage
  • es6-promise-plugin
  • ionic-plugin-keyboard

I unzipped the APK file to find out what going on. I looked at the build Folder in assets/www/ folder which alone was 357MB and it contains JavaScript and MAP files and a 4.5MB CSS file.

How do I decrease the size of the Ionic Android APK file?

like image 212
Praveen Vishnu Avatar asked Jun 22 '18 12:06

Praveen Vishnu


People also ask

How do I reduce the size of an ionic app?

Some of the ways to reduce the apk size: Take prod build - It would minify and uglify the code. Use the following comment. ionic cordova build android —prod.

Can you compress APK?

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 the maximum size of APK file in Android?

Each expansion file can be up to 2GB in size. Users must run Play Store version 5.2 or higher to install 100MB APKs.


2 Answers

You should use the --prod and --release flags when building the APK file for production. It reduces the size by compressing the files.

ionic build android --prod --release
like image 132
suzan Avatar answered Nov 30 '22 23:11

suzan


For people running into that issue with newer versions of Ionic:

In Ionic 4.3 there seems to be a bug in the build scripts. If you run a debug build, and then a release/production build, the www folder is not cleared and you will have all the sourcemap (.js.map) files in the www folder and thus in the final apk file.

See https://github.com/ionic-team/ionic-cli/issues/3954

like image 28
Klemens Zleptnig Avatar answered Dec 01 '22 00:12

Klemens Zleptnig