Development is fine and dandy, but what if you want to deploy a game to a friend's phone or the Android marketplace? We need to see how to produce a distributed version of our game. The easy part is to simply change the Build type option on the Build tab to Distribution. Also uncheck Install to connected device since we have to sign the file that is created. This time when we click Build we get the C:/Users/watracy/AppData/Local/Temp/_S3DTempBuild_/CaveRunner_Android.s3dxproj/bin/CaveRunner-release-unsigned.apk to: C:/Android/CaveRunner-release-unsigned.apk message.
As you can see at the end of the line, the filename includes unsigned indicating that the file has not been signed and will not run on a device.
In order to sign an application, you need a certificate from Android. Why is this needed? It provides a way of assigning ownership of an application to a developer. How does one get a certificate? The Android documentation has some good info at http://developer.android.com/tools/publishing/app-signing.html, including how to get a certificate. Basically, you can generate your own certificate using tools that come with the Java Development Kit. An example of creating a certificate using keytool.exe
is as follows:
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
You will have to answer several questions and specify a password. This will generate a certificate stored in my-release-key.keystore
that will last for 10000
days. The time is important, because the Android marketplace will not accept certificates that expire before October 22, 2033.
Once a certificate has been generated, we can sign our app by entering the following at a command-line tool:
jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore my-release-key.keystore CaveRunner-release-unsigned.apk alias_name
Here, my-release-key.keystore
and alias_name
were specified when creating the certificate and CaveRunner-release-unsigned.apk
is the unsigned application that was created by the Authoring Tool. You'll be prompted for your certificate passwords. The original file will be affected, but the name will not change.
The last thing we need to do is "align" the file. We do this by using the zipalign
tool in the Android SDK and by using the following command:
zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
The –v
sets verbose and the 4
is the byte alignment value and should never change. Specify the original filename and what you want the final filename to be. That's it! The application is ready to go. To get it on a device, we will use the adb
tool that comes with the Android SDK.
To install a program using adb
, use the following command:
adb install your_file.apk
That's it, now the application is on your phone. Now, it is up to you to test your game until you can't stand it anymore. Sometimes, testing can be the longest phase of game development because you need to take the feedback of your testers into consideration and possibly make changes to your game. Once you make changes, it's time for another round of testing—lather, rinse, and repeat until the game is perfect! Our game is far from perfect because the testing process would be another book in itself, but we have built in all the basics and deployed it to a device!
3.144.113.163