Large .apk file built for "Hello World" app

I am new to Corona and I am a subscriber. I have been watching the tutorial videos and just attempted to build my first Android app (a simple Hello World app) using the latest Corona SDK release (CoronaSDK-2011.591.msi). My code consists of one line that prints a “Hello World!” message to the terminal window. Everything built fine but I am shocked by the resultant APK file size. For my simple app, the APK is 4.181MB!!! This is enormous considering I haven’t even written an application yet.

I decompiled the APK file to find out why the app was so large and this is what I discovered:

  1. classes.dex --> 1.361MB
  2. lib\armeabi-v7a\libcorona.so --> 1.358MB
  3. “res” folder --> 423KB

These three files / folders alone cause any app to be at least 3.142MB (without any actual app code). These files make up 75% of the app size. Why are these files so large and why are other libraries / resources included in the APK file if they are not actually used by the app? Is there something I can do to prevent this from occurring? I had expected my app to be less than 100KB (which is only 2% of the actual size). Please help!!!

UPDATE: I also noticed that I have numerous OpenFeint, Papaya and SuperRewards assets and files in my APK file as well. I would definitely not expect these to be included in an app that is not using these services. [import]uid: 77339 topic_id: 13323 reply_id: 313323[/import]

that used to be the case with OpenFeint and 8MB of added data, I guess it will take a while then the assests will be on a pure *if used* basis, however I let Ansca reply on that officially.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 13323 reply_id: 48949[/import]

hmm.-

should be that subscribers don’t get any of the libraries you mention if they are *not* in a “require”

hmm.- could it be that you are building on a non-subscriber account?

.c [import]uid: 24 topic_id: 13323 reply_id: 49081[/import]

@Carlos - Thanks for the reply. I am signing in using my subscriber account and I have authorized my PC that I am requesting the build from. Is there some way that I can check whether or not I am building as a subscriber? [import]uid: 77339 topic_id: 13323 reply_id: 49083[/import]

Hello everyone,

At the moment, Ansca only has one build template for Android which includes all libraries we support, regardless if your app uses them or not. Our iOS builds are smarter and only include what is “required” by your project. In the future we’d like to change our Android build system to only build-in what is “required” by your project, but at the moment this is how it currently works. [import]uid: 32256 topic_id: 13323 reply_id: 49091[/import]

On android market my first game “black box reflections” is 1.2mb

Download apktool, decompile your app, remove any libs you dont need (there are loads spread out over 2 directories, i can go into detail later maybe but i’m on my phone at the moment…)

Can also modify your manifest.xml while youre in there to remove vibrate permissions and change your version codes.

Then i just compress all images, recompile, and use the java signing tool by command line and there you have it, for the sake of literally 1 minute doing this your game goes down in size dramatically [import]uid: 71799 topic_id: 13323 reply_id: 49189[/import]

Thanks for the tip on removing the unnecessary libs. Maybe you (or the Corona staff) could put together a short guide on how to do this and share it with the rest of the community. It would be nice to better understand what each of these large files / directories are for so we can better understand how to shrink our android builds. Thanks again! [import]uid: 77339 topic_id: 13323 reply_id: 49374[/import]

Yeah it’ll be easy enough to put together and i’m sure someone else can refine it. Can throw one over later today after work [import]uid: 71799 topic_id: 13323 reply_id: 49395[/import]

Awesome! I am looking forward to it. It would be awesome to be able to create a small script / windows app to help manage this process. Maybe I can throw something together once I see your guide. [import]uid: 77339 topic_id: 13323 reply_id: 49473[/import]

ok so i suppose I’ll get started with a rough guide (This is all for windows by the way) I’m really only a newbie at corona myself so this isn’t definitive, and obviously i’m not responsible if your app causes a human strain of cordyceps and thus the zombie apocalypse:

1-download apktool (it’s googleable)

2-build your app with corona

3-take the apk and put it in the “place-apk-here-for-modding” folder of apktool (NOTE your apk filename must not contain spaces or it’ll crash the tool, if it does, remove them, you can still put them back later)

4-launch apktool using the “script.bat” file in the apktool folder

5-select options 22, 1 then 9 to decompile your apk. in your apktool root folder, find the “projects” folder, there will be a directory named after your apk

6-see which files you want to delete (for me on xp, going too deep into the “build” folder crashes explorer, so i ignore it). the ones i delete are (note, these may be different for you depending on what you use):

assets->webui
smali->org
smali->com->anything you don’t need (I normally delete everything but **my project’s dir** and **the ansca dir**, but it depends on what you use. ie if you use facebook stuff don’t delete the facebook folder)

7-open the “AndroidManifest.xml” and delete the vibrate permission if you don’t use it; then people won’t be wondering why they need it/phones that don’t support it can still get your app. also delete the internet permissions one if you don’t need the internet (some people get suspicious at this, as it is though i use advertising so i’ve always kept it)

You can also set your version name and version code in here, which i did because whatever version of corona i was using wouldn’t let me use decimal points in the version

8-back in apk tool selet 2 to compress your images

9-select 11 to recompile your apk, you can then re-add any spaces and move it back to wherever you want out of the
“place-apk-here-for-modding” folder (it will have an “unsigned” prefix)

10-i dunno if the sign option in apktool is for debugging only, but just in case i then sign my apk again by hand before uploading to market/testing on device:

[html]
to create the new keystore if you haven’t got one

keytool.exe -genkey -v -keystore yourkeystorename.keystore -alias -keyalg RSA -keysize 2048 -validity 10000

then each time you want to sign it run
jarsigner.exe -verbose -keystore >pathtokeystore>yourkeystorename.keystore yourapkname.apk
[/html]
(just put that in code tags so it doesn’t lose the angle brackets!)
it’ll ask you for password prompts etc in the dos window, fill these out as required.

then zipalign and you’re done
===========

Think that’s about the gyst of it, it looks long but it really takes a minute to do each time once you’ve done it once or twice, and the signing commands i have saved in a text file i just copy and paste

if you copy the apk to your phone first, then uninstall, follow this process and reinstall, you’ll notice a pretty hefty filesize difference

Also, with the same version of corona i noticed it went down even more when i licensed it (i knew that happened for Apple builds but didn’t think it worked for Android builds…) to give you an idea, it was about

~6meg raw
~3meg when i followed the above process with an unlicensed corona
~1meg when i did the process with a licensed corona (same version)

probably a lot of holes and I’m sure people a lot more in the know than me can improve vastly on it, but it’s a good jumping off point if you haven’t done it before i suppose :slight_smile:

just remember to test it first, so you haven’t accidentally removed a library your app actually uses
[import]uid: 71799 topic_id: 13323 reply_id: 49569[/import]

how can we report spammers? [import]uid: 70635 topic_id: 13323 reply_id: 50865[/import]

The spam posting has been deleted. [import]uid: 32256 topic_id: 13323 reply_id: 50955[/import]

Any news on the Android build system with regards to making it smarter so it only includes what is “required”?

I hope Ansca is working to make the Android build system smarter so my games can be leaner and meaner. My game should be a lot smaller because it doesn’t require many extra library features. I’d hate to have to decompile my apk just to strip all libraries that are not required for my game.

[import]uid: 38820 topic_id: 13323 reply_id: 76406[/import]

Wow-weeee! Thank you alickgardiner! I just shrank my game by 3mb and got rid of permissions it didn’t need. Unbelievable all the stuff I didn’t need and my game still installs and runs just fine.

Hopefully Ansca adds support in the next major release of Corona for leaner apk builds ;o)

[import]uid: 38820 topic_id: 13323 reply_id: 76448[/import]

There wasn’t a .bat in my download either. So steps 3-4 did nothing for me. What I did was use help information shown from the apktool from Command Prompt. Basically I used the apktool from the Command Prompt and this forum post as a guide.

Maybe someone can post a download link or more information about the .bat file to make things easier. [import]uid: 38820 topic_id: 13323 reply_id: 86091[/import]

Hi! Good idea to decompile apk file, but i dont understand point 4.
Where is located script.bat? In actually version of apktool, i cant find it.
Please help.
[import]uid: 109747 topic_id: 13323 reply_id: 86089[/import]

Leaner APK’s are a brewing

c [import]uid: 24 topic_id: 13323 reply_id: 87207[/import]

Good news :slight_smile:

Mmmmm… Corona… I’ll have a few brews later today and work on the game. [import]uid: 38820 topic_id: 13323 reply_id: 87266[/import]

I’m testing out Corona and I just built C:\Program Files (x86)\Corona Labs\Corona SDK\Sample Code\Tutorial\AppProgrammingGuide\HelloWorld which spat out a 3,576KB sized file. Have there been no improvements to Corona SDK for Android apk builds in over a year? [import]uid: 172935 topic_id: 13323 reply_id: 121081[/import]

I’m testing out Corona and I just built C:\Program Files (x86)\Corona Labs\Corona SDK\Sample Code\Tutorial\AppProgrammingGuide\HelloWorld which spat out a 3,576KB sized file. Have there been no improvements to Corona SDK for Android apk builds in over a year? [import]uid: 172935 topic_id: 13323 reply_id: 121081[/import]