9

I am developing a hybrid app and now I am in a quandary over phonegap and cordova. Cordova is now in my PC and when I do a

cordova build android

I get an apk that's 3.7 mb, Nevertheless, if I use the build.phonegap.com route, the .apk is only 1.2 mb.

I tried deleting all the unnecessary plugins and even then the build size didnt change

How do I reduce the size of my cordova apk?

6
  • 1
    have you tried cordova build android --release Commented Oct 2, 2014 at 18:30
  • 9
    You can delete all the images located in the platforms\android\res directory if you do want a splash Image to be shown. I reduced my App size from 2MB to 800KB, almost 50% reduction.
    – frank
    Commented Oct 2, 2014 at 18:33
  • @DawsonLoudon: yes, tried --release, that decreased it by only 0.1kb
    – lonelymo
    Commented Oct 2, 2014 at 18:37
  • @frank: DId the trick! thanks. I never created all those images. I suppose they all came in by default.
    – lonelymo
    Commented Oct 2, 2014 at 18:37
  • 1
    They come by default. The images are of various resolutions and size to take into account Screen size and resolution.
    – frank
    Commented Oct 2, 2014 at 18:52

4 Answers 4

6

@frank's comment is the answer
You can delete all the images located in the platforms\android\res directory if you don't need a splash image to be shown. I reduced my app size from 2MB to 800KB, over 50% reduction.

2

Try using "cordova build android --release" this command also reduces the apk file size

Delete www directory before you give build so that old build files will not come to new build.

1

Opening the apk archive, I noticed that no js file was minified, and .map files were big. In my case (I am using TypeScript) map files are only for debug to map js source code to ts source code.

I've installed cordova-minify

npm install cordova-minify --save-dev

I tweaked the hook a little bit to go into the correct folder, disabled the css minifier which messing all up, and delete any map file.

My hook path :

hooks/after_prepare/minify.js

I've also used only one splash screen file (the one for xxxhdpi) not cropped (nor for portrait neither for landscape), following the ionic recommendation

The source image’s minimum dimensions should be 2208x2208 px, and its artwork should be centered within the square, knowing that each generated image will be center cropped into landscape and portrait images. The splash screen’s artwork should roughly fit within a center square (1200x1200 px). (http://ionicframework.com/docs/v1/cli/icon-splashscreen.html)

only one line in config.xml:

<splash src="resources/splash.png" density="xxxhdpi"/>

With all this, I've reduce the size of the apk from 4.8M to 2.5M without losing any features (splash screen).

1

go to platforms folder search png or jpg delete all images you think you added and don't want. Or delete images you dont neeed in your assets/imgs/ folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.