I have developed the app using ionic 3 and now while generating android apk file it 's size getting way too big.
before the API integration The File Size Was 4.8MB once I Started API Interation I just Modified 10 Pages Then The APK File Size became 71 MB
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 unziped the APK file to know what's Happening i Looked Into into
The build Folder in assets/www/ folder weighing 357MB and it contains js files and MAP files
the Rest Assests folder In WWW whis contains the Css File is Of 4.5 MB
how to decrease the size of app for android apk?
You should use --prod
flag while building apk for production. It minimizes the size by compressing the files.
ionic build android --prod --release
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
Please use below command:
ionic cordova build android --minifycss --optimizejs --minifyjs --release
[note:- "ionic cordova build android --prod --release" command have email pattern matching issue in a form, always give invalid email error hence not used that command]
Use below link for more details:
https://ionicframework.com/docs/cli/cordova/build/
Run cordova clean
to cleanup project from build artifacts.
Looks like a bug (not sure) but when live reload is active, the tree shaking feature causes the build to emit several chunk files into the www
folder and i think the more you reload, the more files you'd have in there.
So you'd see files in the form
0.7f0f403f3c9f5914fbce.js
0.7f0f403f3c9f5914fbce.js.map
1.0db885b5a44ebd4ca57e.js
1.0db885b5a44ebd4ca57e.js.map
...and the number goes 0, 1, 2, ... n
You simply need to delete the www
folder to discard the stale chunk files and rebuild your app.
The apk size should be justifiable after that.