3

I'm porting a rather large game engine written in C++ from Windows/Mac to Android. There is a lot of pre-existing code to read assets for games. In addition, there is quite a bit of code doing file system calls (stat'ing the files to make sure they exist, looking up all of the files and directories inside of a directory, etc.)

Right now, I'm focusing on just getting something up and running as quickly as possible, so I'd prefer not to have to rewrite a lot of this. What would be a good way of getting our game assets onto the device and accessing them with minimal changes to our existing standard C++ file system API usage?

I've got some basic support implemented already using the Asset Manager API, but that doesn't support the file system calls and I'm concerned that the 1 MB asset size limit is going to bite me at some point.

I've also looked at OBB, but the tools for creating an OBB file don't look like they are part of the current SDK/NDK. Otherwise, that looks like it would be perfect.

Is it a horrible idea to package up all of the files and just extract them on the SD Card the first time the app is run? Or is there some better way of dealing with this?

Update: I'm also not very concerned on being able to run on a broad range of devices, I am specifically looking at newish tablets, probably the 10.1" Samsung Galaxy tab.

2 Answers 2

0

We ran into a similar problem in developing our (data-file-heavy) app, and we ended up deciding to keep the APK tiny and simply download our data files on first run; they're going to have to be downloaded either way, but a small APK works much better on older devices without a lot of internal storage. Plus, you can potentially rig up a way for people to copy over the files directly from their computer if they have a limited data plan or a slow internet connection on their phone.

The "Downloader" sample app in apps-for-android (confusingly buried under "Samples") is almost a fully-implemented solution for this - you can pretty much just plug in the particulars of your data files and let it do the rest.

1
  • Thanks for the response! I'm not too concerned about supporting older phones at this point (though it's good to know that I should think about that in the future), as we're just trying to get this running on a particular tablet model that's rather new. Also, I'd really like to find a solution that doesn't involve any Java code, just C/C++ from the native activity I've been implementing.
    – matt
    Dec 7, 2011 at 14:16
0

I wrote an app that relies on putting a good amount of native code into the Android filesystem. I did this by packaging the files into the APK as 'resources'. Instead of pushing them to the SD card, you can put then into the application's private namespace, I.E. /data/data/com.yourdomain.yourapp/nativeFolder.

For details on how to accomplish this, you can see my answer to this question.

It's fairly simple to package to just unpack them on the first run and never worry about them again. Also, since they're under the application's namespace, they should be deleted if/when someone were to decide to delete your app.

EDIT: This method can be used to put anything into the app's private area; /data/data/com.yourdomain.yourapp/

However, as far as I know, your application has to be the one to create all the folders and sub-folders in this area. Luckily this is fairly easy to do. For example to have your app make a folder:

Process mkdir = Runtime.getRuntime().exec("mkdir " +localPath);

That works as it would in most linux shells. I walked through the assets folder I packaged into my APK, made the corresponding directories and copied all the native files to those directories.

What you might be more concerned with is the limited Android shell. There are many commands that you might want that aren't present. stat for example isn't available, so all of this may be moot if your native code can't make it's system calls.

2
  • I'm not trying to extract native code, I've got that compiling and loading just fine, it's the game's assets (XML descriptions, art assets, etc.) that I'd like to be able to access easily. Is there another folder that is better suited to that type of data?
    – matt
    Dec 8, 2011 at 22:05
  • See my update. You can unpack that anywhere in your app's folder and have it be accessible. stat however isn't a command that the android shell knows. If this is just a proof of concept type one off project, you can probably compile it for android and stick in system/bin.
    – sarwar
    Dec 9, 2011 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.