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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 07:01:09

问题


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?


回答1:


You should use --prod flag while building apk for production. It minimizes the size by compressing the files.

ionic build android --prod --release



回答2:


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




回答3:


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/




回答4:


Run cordova clean to cleanup project from build artifacts.



来源:https://stackoverflow.com/questions/50988174/ionic-android-apk-file-size-way-too-big-how-to-decrease-the-size-of-app-for-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!