Why isn't Corona using 100% native code on Android?

While developing our newest game Magic Defenders (http://www.youtube.com/watch?v=lw2ITcovcX0), and trying to do a quick port over to Android we immediately hit a few barriers.

Corona SDK seems to be treating both of it’s supported platforms differently. While on iOS it runs natively, with all the benefits of that, on Android it runs on a Virtual Machine. The VM can be a good thing, but in this case (games) it’s bad. We’re limited to the amount of memory allocated to the VM Heap, which is usually pretty low for anyone wishing to take their games to the next level. In our case, we will have to substantially reduce the detail level and spritesheet animation’s fluidity to make it fit into 24MB. For now it was just a matter of using the largeHeap=“true” parameter on the android manifest file to be able to tap into 256MB of RAM. The problem with this parameter is that it’s only available on API level 11 and up (Android 3.0+). I also suspect that some of the performance issues people are facing on some devices are related to this. According to Carlos Icaza Corona on Android is 80% native code.

What I’d like to know is why isn’t it 100% native so that we can do true cross-platform development with the same level of expectations on both platforms? [import]uid: 61899 topic_id: 14237 reply_id: 314237[/import]

Because :
The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code. It provides headers and libraries that allow you to build activities, handle user input, use hardware sensors, access application resources, and more, when programming in C or C++. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.

That’s the first paragraph from the Android NDK Download page.

http://developer.android.com/sdk/ndk/index.html

C. [import]uid: 24 topic_id: 14237 reply_id: 52518[/import]

That makes sense I suppose. But can’t the rendering part of Corona be ported to native code or something (don’t know if it isn’t already)?
In this message http://bit.ly/niTROL from a discussion regarding NDK and memory limits someone asked if it was OK to use native code in order to laod and process large bitmaps that wouldn’t fit into the VM heap. It seems to be possible. All I want to know is if there’s a way to do this in Corona. If it isn’t possible at all then anybody wishing to port their games to Android is best advised to take special care of the memory usage and keep it below 24MB at all times, since that seems to be the general limit on higher end devices. Honeycomb tablets have a 48MB limit. 16MB will make sure the game runs on everything.

BTW, can I make a feature request to be able to set some manifest options that would help a bit in this case? Namely the largeHeap=“true” option and being able to set the minSDKVersion (minimum of 8 of course) and also the “supports-screens” parameter. There is a serious lack of configuration options for Android right now. [import]uid: 61899 topic_id: 14237 reply_id: 52526[/import]

Actually, most Corona objects are OpenGL so we eat the texture buffer memory as much as anyone else out there even if you were to write in pure C++.

Corona, and some of my competitors, use TextTure Memory - so we are limited to the OpenGL texture buffer memory bandwidth.

And no, in Android you can’t get away without touching the VM. Corona is OpenGL/C++ with the JNI Bridge, just like any NDK app out there.

C.

ps: you can actually change the manifest - look at config.lua. [import]uid: 24 topic_id: 14237 reply_id: 52537[/import]

@Carlos - Does this mean that for anything less than Android Honeycomb (e.g: 2.2) that we are limited to only 24mb of memory?

If this is true, how can we use a large number of spritesheets for a character on the android platform? I assume there is a loading time associated with creating a new sprite so setting one sprite to nil and loading a new one during animation would not work?

Thanks
ML [import]uid: 63352 topic_id: 14237 reply_id: 52548[/import]

u are limited to whatever the texture memory buffer is on the system.
.c [import]uid: 24 topic_id: 14237 reply_id: 52552[/import]

If you limit the app’s memory usage (total, not just texture) to 24mb you’ll be fine on most devices. Some phones may have a higher limit, but it’s best to err on the safe side.
I’ve watched the memory allocations log for a while and it seems you can go a bit over the max heap size sometimes, as some memory is allocated as native and not as VM.

PS: When Corona implements compressed textures support (it’s on the roadmap), our lives will be much better :smiley: [import]uid: 61899 topic_id: 14237 reply_id: 52558[/import]