I’m afraid so but it still breaks. I’ll go back to the web overlay and retry different scenarios. [import]uid: 8271 topic_id: 15566 reply_id: 65103[/import]
Everyone,
I actually work on the code for Android… so please let me explain how it really works. Nobody knows how it works better than I do. 
An Android APK is really a zip file. The files in the resource directory are inside the APK file, therefore they are compressed within a zip file. The Lua io API such as io.open() is unable to open/extract files inside a zip file, thus it cannot open files within an APK. This is true of the io API on all platforms (Mac, Windows, iOS, and Android).
Now, the reason that the Lua io API can access resource files from an iOS package is because it is NOT a compressed file. The iOS package file contains its own directory structure which you can get an absolute path to its contained files that are accessible in the C language, which is what the Lua runtime is written in.
So, this presents an interesting problem with Android APKs. The C/C++ side of Corona and the Lua runtime are unable to access resource files within the APK because it is really a zip file. We have to access these files differently than how we do it compared to files outside of the APK. We do access these files via special Android function calls on the Java side. We’ve set up our Ansca made Corona APIs to be able to identify if it is a file within the APK or outside of the APK and open it seamlessly for you. However, the Lua “io” API was not made by Ansca but by the developers of Lua, so it has no understanding of what an APK is and how to access its contained files. So I hope this makes the problem clear to you.
That said, we’ve implemented some special handling. Calling system.pathForFile() on certain file types will cause Corona to automatically extract that file and copy it to an outside directory. It’s a hack, not a good solution because it is wasteful on storage space, but it allows Lua io APIs to access certain file types.
system.pathForFile() will auto-extract all file types EXCEPT the following:
- *.html
- *.htm
- *.3gp
- *.m4v
- *.mp4
- *.png
- *.jpg
- *.ttf
This means that the above file types cannot be accessed by Lua io API. All other files will be automatically extracted when calling system.pathForFile() first. This is also why you can’t access your HTML file. The reason that the HTML file is not auto-extracted is because typically images are linked to it as well so Corona would have to auto-extract image files too to make the web page appear correctly… but we definitely don’t want to do this because images typically take a huge amount of space on storage.
So, there it is. You might want to bookmark this posting.
[import]uid: 32256 topic_id: 15566 reply_id: 65109[/import]
Thanks for the detailed info, Joshua. Bookmarking for sure. [import]uid: 49447 topic_id: 15566 reply_id: 65111[/import]
Thank you very much Joshua, that’s really good to know.
I still need a way round my problem, so what I intend to do (and hope to try in the next hour) is to store all my html files as .txt files - renaming them from html in the copy process from the resource to the temporary directory.
Does this seem reasonable to you?
Thanks again,
Matt. [import]uid: 8271 topic_id: 15566 reply_id: 65206[/import]
Matt,
Renaming your HTML files to TXT files will indeed work. When you call system.pathForFile() on them, it will extract and copy the TXT files to an external directory and pathForFile() will give you the new location of that copy. You can rename files via the os.rename() function. Also, the newest daily builds definitely do support resource files in subdirectories now, so feel free to give it a try.
http://developer.anscamobile.com/reference/index/osrename
I apologize for making you jump through hoops on this. It’s an annoying limitation for sure. Something for Ansca to think about how to improve upon later. [import]uid: 32256 topic_id: 15566 reply_id: 65280[/import]
Thanks - I did try and it definitely worked.
I’m fortunate in that my only resource files are CSS and JavaScript files.
Thanks for your help!
Matt [import]uid: 8271 topic_id: 15566 reply_id: 65287[/import]
Hi Guys, just read through these postings and I’m still not sure what I am doing wrong. I have just written my first app and I am trying to load it onto an HTC Desire. All my files are in one directory on my PC. There are many more files in that directory that aren’t necessarily being used (e.g Photoshop psd files) but I assume that if they are not being called by my lua files then they don’t get included in the apk file.
I build the app with the androiddebugkey and install the resultant .apk file onto my phone using the dropbox method. The icon appears in the applications area, but I get the error: this application has been corrupted message. I have checked all my “require” file names and they are all correctly cased and spelled. I am not calling anything from any other directory. The only native call I am using is the native.ShowAlert() function. Could this be anything to do with it?
Update: SORRY HOLD OFF TRYING TO HELP ME. After posting the above message, I thought I would look at the spellings of the “png” files and they were miles out with upper and lower cases. I am building again so hopefully that should be the answer - Adrian
By the way is 24mb excessive for an app?
Cheers
Adrian [import]uid: 83824 topic_id: 15566 reply_id: 65698[/import]
Glad you solved the naming.
No, I doubt 24mb is large. 240mb might be, but there’s plenty much larger in the iOS app store, at least. [import]uid: 8271 topic_id: 15566 reply_id: 65716[/import]
Adrian,
It depends on what you mean by 24MB. Do you mean the total size of the APK file is 24MB? As mentioned that is not a problem. However, if you are using some code to look at your texture memory and that exceeds ~20MB it probably won’t work. I had to get my texture memory down under 20MB to get the app to reliably run. Sometimes it would work, then crash. Once I got it under 20MB of texture (loaded at any one time) I was fine.
Ken [import]uid: 16734 topic_id: 15566 reply_id: 65722[/import]
@KenRogoway is that something you’ve only seen on Android? [import]uid: 8271 topic_id: 15566 reply_id: 65901[/import]
Yes. My game originally took 36MB of texture memory. This worked fine on the iPhone, but not on the Droid phones. There are a number of posts in the Ansca forums about texture memory on Android based phones. Basically it boils down to the fact that there is no standard and no easy way of knowing how much texture memory is available. I kept whittling away and my textures until I got it to work on the Droid. At 24MB of textures it would sometimes load, then crash shortly after. At 20MB of texture it would almost always load and very rarely crash when the texture memory went up a little. Under 20MB seemed to be the right value for stability. Different phones will have different limits. Do whatever you can to minimize your texture usage if you want to run on Android devices. [import]uid: 16734 topic_id: 15566 reply_id: 65984[/import]
Can you give some pointers on how you can reduce texture memory?
My game uses around 23MB and I thought that was okay until I came across this… [import]uid: 64174 topic_id: 15566 reply_id: 65998[/import]
I have two main types of textures in my game. One is for large (full screen) images. The other are the sprite sheets.
Since most of the unique full screen images were for my help pages, I made sure that I didn’t preload those, just load a page on demand, then remove it when going to the next page.
As for the sprite sheets I did two different things. I had my animations at 30 FPS. I dropped that down to 15 FPS (basically throwing out half the frames) and make new sprite sheets. This got me really close, but not quite all the way. The final thing was to reduce the size of those sprites and then scale them up during playback. This got me under 20MB of textures loaded at any one time.
For the batch scaling of my images I used XnView’s nconvert.exe. Then I packed all of my animations into a sprite sheet using Texture Packer (a VERY nice 3rd party tool that I highly recommend).
Hope that helps. [import]uid: 16734 topic_id: 15566 reply_id: 66004[/import]
Thanks a lot for the info Ken! 
[import]uid: 64174 topic_id: 15566 reply_id: 66039[/import]
Everyone,
As of the latest daily buidls, your app should no longer crash when loading too many images. Instead, the image will just fail to load. We’ve also tried to make the image loader a little more intelligent by loading the images at 16-bit color quality (taking half the memory) on low-end devices with low RAM. We still have more to do to make this easier on your guys, such as provide a “low memory” warning event, but above all we wanted to make it more stable and make it easier to do high color quality on high-end devices and yet still support low-end devices. [import]uid: 32256 topic_id: 15566 reply_id: 66063[/import]
Thanks guys, as I am developing my first Corona app I just wanted to see how I was doing size wise. I don’t think I have any texture mapping - just a png file that acts as a background.
Thanks for all your replies though (although I can’t understand all of them!!)
Adrian [import]uid: 83824 topic_id: 15566 reply_id: 66429[/import]
I have another question. As I understand from Ken, around 20 MB of texture memory usage is good…
What is an optimum value of total Memory used? I think collectgarbage(“count”) returns memory used.
How often do I call collectGarbage()? [import]uid: 62560 topic_id: 15566 reply_id: 67147[/import]
@Time Plus,
You should add the function that JRQ posted at the link below to you main.lua.
This function will output your memory usage, but only when it changes from the last time it checked (every frame).
I’d be surprised if you use more than a meg or two of non-texture memory. My game only uses 1 MB of non texture memory.
[import]uid: 16734 topic_id: 15566 reply_id: 67162[/import]
Thanks! My game uses some 700K so I guess I must be OK! [import]uid: 62560 topic_id: 15566 reply_id: 67206[/import]
I’ve experienced this problem when building to Android. For me the problem has usually been that I was using
require(“Module”)
when the file where the module is was
module.lua
Notice the uppercase/lowercase difference. Changing either the require call or the filename fixed the problem.
This problem is usual if you’re developing under OSX, since by default it installs a case-insensitive filesystem. [import]uid: 93532 topic_id: 15566 reply_id: 70338[/import]