Android: Assets, not Resources

HamQuest, in its current incarnation as a SilverLight application, is actually rather small-ish, codewise.

The real content consists of images and xml files describing the various objects in the game.

In fact, I made a concerted effort to remove as much from the application itself, and put it into the xml configuration files.

In the move to Android, I found the XML reading facilities to be a bit less than what I was used to in SilverLight.

See last post.

But forging ahead, because (after all) I still like to have all of my configuration in xml rather than having to convert it to something else.

I learned about XmlPullParser.

It reminds me vaguely of TinyXML.

I used to use TinyXML back in my C++/SDL days.

I didn’t like it then.

I don’t like it now.



I spent a lot of time googling things like “reading xml files in android” and the whole gamut of things like that.

Apparently, if a person is not making an XML feed, or reading something from the Android resource files, they aren’t using XML.

So the documentation takes a little while to sort through.

Eventually, you wind up at XmlResourceParser, and recommendations that xml files should go into res/xml.

Which is true, if you aren’t relying on a folder tree of xml files to feed the engine of your game like I am.

But I try it anyway, with many foiled plots to get my data from xml.

Until eventually I come to the conclusion that my XML files are Assets, not Resources.

And so I move them into my assets folder, and even into sub-folders (which res did not let me do), and I can even use capital letters in the name of the file (again a no with the res directory).

Finally, I can open an read my proprietary XML configuration files.

Unfortunately, I have to have a state machine that reads them in.

No, the org.w3c.dom classes would not help here. My code would be just as iterator-iffic.


Now I’m on to phase 2 of this, which may or may not be trickier.

You see, the XML configuration files contain a number of types of data.

Most of them are strings, bools, ints, and floats.

But every once in a while, I needed something else, which lead to a scheme by which reflection is used to load a custom object based on an attribute that holds the name of the class.

Java, it seems, has had reflection capabilities for quite some time.

They call it “introspection”, but I’m not here to quibble over how a language contemplates its navel.


I use SVN.

Use code.google.com to store my stuff.

Yes, that makes it open source.

No, I’m not concerned about people ripping my stuff off.

Have you looked at how much crap is up there?

I’m like the Millenium Falcon adrift in a Star Destroyer’s jettisoned garbage.

Maybe one of these days,  I’ll get some cloud space to store my stuff on.

However, for whatever reason, I’m having troubles getting an eclipse workspace to play nicely with SVN.

It has mostly to do with the generated resource files.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s