An Android APK is really a zip file

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.

转载于:https://www.cnblogs.com/superchao8/archive/2012/04/23/2466101.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值