Google+ Badge

Thursday, December 9, 2010

I published my first Android game tonight

Must say this is a big ball of stress that I can throw back into the void. I began working on the game in October while I had some time off between my old and new job. Always good to take a little time off after giving notice.

If you have an Android phone and like logic puzzles do a search on "Grid Hunt" on the Android Market and give it a shot. The game is free. I decided to go the AdMob route to see how that works. Seems like a good time of the year to release a game. Lots of people will be getting new phones and people will be taking time off so they will have some extra gaming time. I know I hit the market every so often to see if there is something new to play for a few minutes.

Actually writing the game was the easy part. It became a real headache when I tried to tie in AdMob. There is not much in the way of documentation which is very unlike the rest of my Android experience. First off I wrote a game so I was using the full screen. I had forgotten that I plugged my view directly into the activity instead of doing it via the XML file. I put all the AdMob stuff into the XML and of course nothing happened.

I changed the code to use the XML to drive the view which meant a shuffle of some other things as I was not using the XML based constructor. I got that working but no AdMob so I shoved in a simple label and it painted on top of my game screen. I realized my game code was a custom view so I needed to tell the layout manager what my size happened to be. I added the following code:

* We want to take up almost all of the screen
protected void onMeasure(int width, int height) 
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int dispWidth = display.getWidth();
int dispHeight = display.getHeight();

setMeasuredDimension(dispWidth, dispHeight - 48);

This put the label at the bottom of the screen. I was then able to piddle around with the AdMob code to get it to appear. I really don't remember everything I did to get that to happen. I needed to get some options configured and I finally got some output in the less of reliable Android log window of Eclipse. I was able to get the special code line from the log console to show the test ads.

I configured a private key and used the really handy Eclipse export signed APK menu item and created a nice ready to roll APK.

I wanted to get this rolling tonight but I wanted to clean up the help text and add some separators in the options dialog. I plugged in my phone and it would not install the app! What the heck is going on here? I have been using my phone at work to develop our app there and I have been using IntelliJ. I did find a quick answer on the web. I just need to adjust the time out value in Eclipse. Then it started working again but not until my wife closed the door to the office due to my choice words of "I don't need to to ^%%$# happen to me tonight!"

When I tried to pull up the options screen it crashed. How could this happen? Turns out when I switched to the other XML style view loading I used same variable name hiding the one in the main class. I thought I had that warning enabled in Eclipse but I did not as I had started a new Eclipse workspace when I renamed parts of the project which annoyed SVN. I hate that part of Eclipse, I want my workspaces to all have the same warnings settings. I enabled nearly all warnings, fixed a few of those in the code and did the easy fix for the view issue. Once I figured it out so I was back on my way to having a fully functional app.

The Android Market Website was really easy to use. I plugged in my information and uploaded the file along with screen shots and descriptive text. I knew I had an issue with new ads not appearing but I though that would only happen after it was on the market. I was wrong. Ads still were not working, you got the first one but it never changed. So I checked the AdMob site and set it to override the interval then the ad did not show up at all! I unpublished the app and started doing Google searches.

I found out I have to set the interval which I tried to do in the attrs.xml file but I had no luck there. I never got the other attributes to work via the XML file but I did not really care to override the base colors. Now I needed something to work. I piddled around with that for too long and then found I could just do it directly in code so I set it up for 30 seconds. It worked as I tested the phone via the debug cable so I put it out on the web again after upping the version numbers.

Of course I sent out a note to all my buddies that have Android phones and put an update on my LinkedIn profile. Finally the brain dump on the blog. I sure learned a lot and I still think this is easier than the iPhone hell I have been going through with just getting a developer certificate. I still can't put my iPhone code on a stinking device.

I know I have been using a lot of things I learned from my game development for my work development. I was able to really chug along today at work on the login screen that I am redoing. Now I can take all my market place set up knowledge and use that too. We will not use Ad Mob for the app I am doing at work but if this game makes me a few bucks I am sure I will write a few more apps outside of work and I plan on using ads again. Since I now have real working code to look the next time it should fall into place really easily.

It will be interesting to see what comments I get on the game, how much money I am able to make off of it and how many downloads occur. I have some ideas for a two player mode which would make a really nice update if the games gets a few eyes on it. Always good to have an update after the game has been out a bit and I don't think there are many two player games out there. This will not be two playing at same time but one player solving the board then another player getting the same board and trying to beat the time or each player designing a board for the other to see who can screw the other one up the worst.