My first Android app
I published my first Android app last night. It's a pretty but fairly boring game (called RockinRoll) that I originally did for the iPhone, which I ported mostly as a learning exercise. The game has nothing to do with music; it is a match-3 style game crossed with a 2D physics engine that is hooked up to the phone's accelerometer. Different colored stones come out on top and fall, and how you tilt the phone controls where they fall toward. Making 3 or more of the same kind touch makes them disappear, and you get points. There are a few kinds of powerups that help you out too.
Here's one of the powerups about to go off:

The iPhone version of the game is written in C++, with as little Objective-C as I could get away with. I do not approve of Objective-C. It includes rendering code for both OpenGL ES 1.1, which was available on 2nd generation hardware, and OpenGL ES 2.0 which uses programmable shaders, and was available on 3rd gen hardware and up. The shaders let me do some special effects, and much better anti-aliasing than the 1.1 renderer. The iOS version of the game looks roughly like this:

Android applications are written in Java. Google also provides a native development kit, which lets your Java application load separately compiled C or C++ code and make calls into it. I tried pretty hard to port the GL ES 2.0 rendering path to Android; I have a Nexus 1, which supports ES 2.0 and it looks quite a bit better. Alas, nothing doing. I could not get it to work. I am pretty certain that the ES 2.0 support is just busted, either in the phone itself (unlikely) or in the NDK (I hope). There is a newer release of the NDK available than what I built with, so I should probably try again. Anyway, there are no shaders in the Android version, which looks about like this:

Some random thoughts on the two platforms:
- Sound on Android is tremendously easier than on iOS. It is still harder than it should be, but Core Audio on iOS can provoke true rage.
- When I published RockinRoll for the iPhone, I uploaded it and clicked publish and waited for over 5 weeks while Apple debated its worthiness for their platform. Last night I clicked publish on the Android Market backend, waited a few minutes, and it was available to my phone.
- Google's architectural aesthetic is much better than Apple's, IMO. The APIs are better thought out, easier to use, and Java is a much better language than Obj-C.
- Apple's technical domeepentation sucks meep. Google's is better, but still sucks.
- The busted shader layer really bums me out.




Sep28 '10
posts
46.9k rads
46882 rads
#
*jealous
Sep28 '10
posts
254k rads
254010 rads
#
Nice. Hard to get my head around how those two diagrams can look so different. How much extra engineering effort was it to re-jigger for Android?
Tried to download it just now and couldn't find it on the market. Found a reference to it on another site via QR code that brought me to a "Not found" page on Market.
Sep28 '10
posts
319 rads
319 rads
#
It shows up for me still, tho I had to reboot my phone before it would show me up-to-date data; it was still showing me what was cached from last night. The app declares that it needs Android 2.1 or better, which may not be entirely true; I should re-examine that.
In terms of code changes:
- there are about 600 lines of new Java code, which are responsible for app startup and lifecycle, setting up OpenGL, receiving touches and passing them on to the native layer, reading the accelerometer, running the sound engine. this replaced about 1500 lines of equivalent iOS code, with the sound layer making up most of the difference in size. there are about 500 lines of C++ code in the Android version that just handle interfacing to the Java side. JNI is a meep.
- time is very different on the 2 platforms. on iOS, time is a floating point number of seconds; on 1 frame "time" may be 1.0 and on the next, it will be 1.03. on Android, time is an integer number of milliseconds. all of the code that did timing related stuff - anything with animation, pretty much - had to be changed.
- loading resources is quite different, and was much easier on iOS: you pretty much just open a file and read it. that's how it would be on the Java side on Android too, but for the C++ code loading textures, and using save game files, it had to call back to Java and let the Java layer do all the I/O.
I guess that was about it. The GLES 1.1 code worked as-is once I got initialization working, as did most of the actual game, aside from the time issues. It was probably 2-3 weeks of actual work to port it, vs about 10-12 weeks for the original iOS version (including the ES 2 stuff, which was about 50% of that).
Sep28 '10
posts
319 rads
319 rads
#
Wotak, it's a skill that can be learned very cheaply these days, if you have patience (and a certain degree of OCD helps a lot). The Android dev tools are all free, will run on Linux, Windows or Mac, and most new phones (I think?) will let you load apps over the USB port for testing and experimenting. Give it a try!
Sep28 '10
posts
16.6k rads
16646 rads
#
I wrote a "paperweight" app for my blackberry, and by wrote I mean throw against the wall.Back to the old Blackjack now, funny how that piece of meep has outlasted 2 new phones. Got windows 6 loaded on it finally so I might actually stick with it for now. Hats off to your programming skills, it seams like pure voo-doo to me.
Sep28 '10
posts
4303 rads
4303 rads
#
Turns out I'm not very good at this game, but it runs great on my Galaxy S: Runs smooth and the movement response feels good.
Sep28 '10
posts
319 rads
319 rads
#
Ooh, now I'm the jealous one. The Galaxy S looks awesome. Any complaints with it?
Thanks for looking! I updated it last night and lowered the required OS to 2.0 so maybe it will show up in the market for more people.
Sep28 '10
posts
4303 rads
4303 rads
#
The Galaxy S is great. Mine is the Captivate from AT&T. It looks great and feels solid. Its fast as meep, especially if you apply the Lagfix (i used ext4) and run the 1.2 overclock kernel. I'm getting Quadrant scores of 2000-2250.
My only real complaint would be the GPS fix time. Its taking 35-50 seconds to get anything closer than 1000m. There are some suggested fixes. but I'm not having much luck.
Sep29 '10
posts
3318 rads
3318 rads
#
It runs smooth on my evo and I like how I can hit the back key without any "are you sure you want to quit" bullmeep, instead it pauses and is ready to start when I go back to it.
Sep29 '10
posts
319 rads
319 rads
#
Saving your game when you quit and restoring when you start again was one of the hardest things to port from the iPhone, oddly.