Load raw file under res/raw via openRawResource(R.raw.idxxx) failed

419 views
Skip to first unread message

Eric Wang

unread,
Oct 15, 2009, 5:26:14 AM10/15/09
to andro...@googlegroups.com
Hi all,

I have data.pak which is a compressed file, and bundled as res/raw/data.pak.
While read the raw data by getResources().openRawResource(R.raw.data), it crashed.
Have read a lot of stuff in SDK docs and the posts in the groups, couldn't figure out the reason.

According to the SDK doc, maybe assets/data.pak is a solution, but don't know how to bundle
as assets/data.pak.

Thanks in advance!
- Eric

Rockthesmurf

unread,
Oct 15, 2009, 7:30:38 AM10/15/09
to android-ndk
Hi there,

I too am interested in having a single raw data file included in my
project, I would like to be able to read this file from the native
code - could anyone suggest the correct way to do this? E.g. Where I
need to put the data file (I am using Eclipse) and what I have to do
to give the native side either a file handle, or memory offset and
size?

Many thanks,

Steve

Jack Palevich

unread,
Oct 15, 2009, 9:27:56 AM10/15/09
to andro...@googlegroups.com
Unfortunately there is currently a limit on the size of an individual resource. This is because the resource manager makes an in-your-application-heap copy of the resource, and your application heap size is limited by the OS.

If you wanted to pursue the all-data-in-the-apk strategy, you could try cutting your data up into medium-sized chunks, say 256K and only read a few of them into your heap at one time.

Perhaps the simplest approach would be to cut up your file into 256K chunks, store them all in the APK, and then at runtime read the chunks one-by-one and use them to create an ordinary file (which you could store in your apk-specific data directory, or on the sd card)

Another approach, which avoids putting two copies of the data on the device, would be to store the big data file on a web server, and download it at run time using the apk. I experimented with that for Quake, and it worked great, except that the web server gets hammered when I do a new release. Some games use bit torrent to avoid hammering their web servers.

Dianne Hackborn

unread,
Oct 15, 2009, 1:12:36 PM10/15/09
to andro...@googlegroups.com
You can also store you resources on the .zip uncompressed, so they don't need to be read into a buffer.  One person had a great idea to put all of their data inside of a .zip that was then placed in the .apk -- the .zip won't be compressed in the .apk, so you can use the API to get a file descriptor and its position in the .apk, and directly read from it.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Reply all
Reply to author
Forward
0 new messages