How to create a private key for signing Android apps

To create a private key to sign your Android apps with, you need to run the keytool command (installed when you install a Java development kit) as follows.

keytool -genkey -v -keystore myandroid.keystore -alias myandroidkey -keyalg RSA -keysize 2048 -validity 10000 -dname "O=Acme Ltd"

Replace Acme Ltd with your company name.

When the tool runs it will prompt you for a password and then generate a file called myandroid.keystore. You will need this file, your password and the key’s alias (myandroidkey in this example) to sign your app.

To see the details of your key use the following command:

keytool -list -v -keystore myandroid.keystore

For more information see the Link to Signing Your Application page page in the Android developer’s documentation.

Tutorial: Creating your first Unity Android App [2015 Update]

This is a quick, step by step guide to creating a simple app for Android using Unity. This tutorial is for windows but other then the install instructions it should work for other platforms. By the end of this tutorial you will have created an app that displays a red spinning cube on a blue background running on your Android device.

 

Setup the Android SDK

To create an Android app you need to install the Android SDK, which can be downloaded from here. I installed the SDK to c:\android-sdk

If you don’t have a Java Developer Kit (JDK) you will need to download one from here before you can install the Android SDK.

Once the SDK is installed, you need to add the Android 5.01 (API level 21) package to it. Run the SDK Manager and use it to download the API level 21 packages (it should all be selected by default). See here for more info.

Setup your device for testing

Next, you will need to install the USB device drivers for your Android device. Whilst it is possible to use the Android Emulator, its performance is pretty bad so you are much better off testing on a real device. If you are using a “Nexus” device you can install its USB drivers using the SDK Manager, otherwise you will need to install your device’s specific drivers. See here for more info on setting up your USB driver.

You will need to enable USB debugging for your device. On Android 4.2 and higher, the Developer options screen is hidden by default. To make it visible, go to Settings -> About phone and tap Build number seven times. Return to the previous screen and select Developer options at the bottom and turn on USB debugging. On older versions of Android, go to Settings -> Applications -> Development and turn on USB debugging.

To test that everything is set up, plugin in your device, open a cmd prompt and run the following commands :

cd \android-sdk\platform-tools
adb devices</pre>

Your plugged in device should be listed. If not check your device as it may be prompting you to authorize your PC.

Setup Unity

Download and install Unity 3D to its default location. The installer can be downloaded from here. Run Unity after the install is complete. You will need to create/login into a Unity account when you first run Unity.

Also, if you have never installed Unity before on your PC you will also be given the option to run Unity Pro for an evaluation period or to run the Free edition. This tutorial only requires the Free version of Unity and I suggest you start with the Free version. You can always upgrade at a later date. You can compare the different versions of Unity here.

Creating the app

Start Unity and select Create New Project in the Project Wizard, name the project RedCube and click Create (if you already have a project open, select File -> New Project to create a new project).

Change the screen layout

In the drop-down box in the upper right of the screen make sure 4 Split is selected.

Create the cube

From the GameObject menu select 3D Object and then select Cube. Make sure that Cube is selected in the Hierarchy panel (3rd panel along the top of the screen), then in the Inspector panel (far right panel) set the following values for the cube:

  • Position: x = 0, y = 0, z = 0
  • Rotation: x = 0, y = 45, z = 45
  • Scale: x = 2, y = 2, z = 2

Position the camera

Select the Main Camera  in the Hierarchy panel and set the following properties for the camera in the Inspector panel:

  • Position: x = 0, y = 0, z = -5

Add a light

From the GameObject menu, select Light and then Point light. Set the following properties for the light:

  • Position: x = 0, y = 0, z = -5

Test the scene

Click on the Play button (top center of the screen). You should now see the lower left panel switch to the Game tab and you should see a white cube on a blue background.

Press the Play button again to stop the game.

Note, this important: Unity allows you to make changes whilst the game is running but these changes are lost as soon as you stop the game running. This is great for debugging but is an easy way to lose you changes :)

Save your project

Speaking of losing your work, now is a good time to save your project. Select File -> Save Scene, enter RedCubeScene as the name for the scene when prompted. Then select File -> Save Project to save the project. Remember to save your work regularly.

Making the cube red

Right click on the Assets folder in the Project panel (3rd along the bottom) and then select Create -> Material, name it RedMat. In the Inspector window click on the white color block next to Main Color and then select a red color from the color picker.

Drag the RedMat material from the Project window onto Cube  in the Hierarchy window. The cube should now turn red in the various scene panels. If you are only seeing a wireframe outline of your cube in the Scene panels, select Textured from the Scene panel drop down menu that says Wireframe.

Making the cube spin

In Unity, scripts are used to add behaviors to objects and to create the logic of your game. We will use a script to make the cube spin.

Right click on the Assets folder in the Project panel and select Create -> C# Script, name it Spin.

In the Inspector window click the Open button, give it a moment for the MonoDevelop IDE to launch. You should see a code editor window. Modify the code to read as follows:

using UnityEngine;
using System.Collections;

public class Spin : MonoBehaviour {
    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {
        // rotate at 90 degrees per second
        transform.Rotate(Vector3.up * Time.deltaTime*90);
    }
}

Save the code (press Ctrl+S) and then switch back to the Unity editor.

Drag the Spin script from the Project window onto Cube in the Hierarchy window. Click on Cube in the Hierarchy panel. In the Inspector panel you should see that the cube now has the Spin script (and the RedMat) assigned to it.

Press the Play button. You should now see a red cube spinning in the Game window. Press Play again to stop the game.

Building the app

Now that we have the app completed, we need to build it for Android.

Select Edit -> Project Settings -> Player

In the Inspector window under Cursor Hotspot click on the tab with the Android icon (4th tab along).

In the Other Settings section change the following values:

  • Bundle Identifier = com.rabidgremlin.tut.redcube

Now, select Edit -> Preferences and then select the External Tools section. Click on the Browse button next to Android SDK location and select the root folder of your Android SDK install (c:\android-sdk in my case).

Next plug-in your device.

Now, select File -> Build & Run, this will open the Build Settings window. Select  Android under platform and then click on the Build & Run button, when prompted for a name for the .apk file enter in RedCube.

A build dialog will pop up and you will see the app being built followed by a message about the app getting pushed to your device.

Have a look at your device, you should see the RedCube app starting up, followed by a red cube spinning on a blue background.

Congratulations you have created your first Unity Android app !

What next?

If you are interested in creating 2D games with Unity then check out my Run Bunny, Run! tutorial series.

Otherwise go and complete the some of the Unity tutorials. These will give you a good understanding of how Unity works. Also check out the very comprehensive documentation and the very helpful community.

Have fun :)

M is for Monkey – the evilest testing tool around

I do a heaps of Android development and whilst it appears straightforward there are quite a lot of subtleties, particularly when dealing with threads and UI updates, that generate all sorts of app crashes.

Unfortunately these race conditions are often very hard to reproduce. Thankfully (and evilly) we have the monkey testing tool. Set it loose and it frantically taps and swipes away, switching activities, causing mayhem and inevitably crashing your app.

Running monkey is really easy just, run the adb tool with the following parameters:

adb shell monkey -p your.package.name -v 500

Also make sure you run monkey on your app, on different versions of Android, especially if you use the support libraries which don’t always behave the same way on different OS versions. You will be surprised at what goes wrong.

Let loose the monkey and despair ☺

Word War III – Dev Diary – 03: Some Structure

Next up is some “boring” housekeeping work on the code. Eventually the game will consist of four screens. If I keep up with my current approach of putting everything in a single script things will get pretty messy, pretty fast.

Luckily there is a better way which is highlighted in the Futile videos and in the Banana Demo project . The idea is to subclass the FContainer for each screen and then add and remove these objects from the Futile stage.

First off I create an enumeration defining each of the screens:

public enum ScreenType
{
    TitleScreen,
    GameScreen,
    ScoreScreen,
    HelpScreen
}

Then I created a base class which, extends FContainer, for my screens:

public abstract class Screen : FContainer
{       
    override public void HandleAddedToStage()
    {
        Futile.instance.SignalUpdate += Update;
        base.HandleAddedToStage();
    }

    override public void HandleRemovedFromStage()
    {
        Futile.instance.SignalUpdate -= Update;
        base.HandleRemovedFromStage();
    }

    public abstract ScreenType Type
    {
        get;
    }

    abstract public void Start();

    abstract protected void Update();
}

The Start() method will be called just after the screen object is created. This is where we will create all our FSprites etc for the screen. The Update() method is where we can stick any logic that needs to be updated every frame. I overrode HandleAddedToStage() and HandleRemovedFromStage() to clue Futile into the fact that it needs to call (or stop calling) the Update() method. Lastly I created the Type property so that the main script can figure out what type a screen is at run time.

Here is the (redacted) code for the TitleScreen:

public class TitleScreen : Screen
{
    private FButton startButton;
    private FSprite bg;
    private FSprite nuke;
    private FSprite skyline;
    private FSprite title;

    override public void Start()
    {
        bg = MakeSprite("Background.png", 0f, 0f);      
        AddChild(bg);               

        nuke = MakeSpriteWithBaseLine("nuke.png", 0f, -Futile.screen.halfHeight + 50);      
        AddChild(nuke);

        skyline = MakeSpriteWithBaseLine("skyline.png", 0f, -Futile.screen.halfHeight);     
        AddChild(skyline);      

        title = MakeSprite("Title.png", 0f, 180f);      
        AddChild(title);

        startButton = MakeButton(0f, 0f, "START");
        AddChild(startButton);      
        startButton.SignalRelease += HandleStartButtonRelease;
    }

    private FSprite MakeSprite(string name, float xPos, float yPos)
    {
        FSprite sprite = new FSprite (name);
        sprite.x = xPos;
        sprite.y = yPos;

        return sprite;
    }

    private FSprite MakeSpriteWithBaseLine(string name, float xPos, float yBaseline)
    {
        //...
    }

    private FButton MakeButton(float xPos, float yBaseline, string buttonText)
    {
        //...
    }

    public override ScreenType Type
    {
        get { return ScreenType.TitleScreen; }
    }

    override protected void Update()
    {
        // do nothing
    }

    private void HandleStartButtonRelease(FButton button)
    {
        Main.instance.GoToScreen(ScreenType.GameScreen);
    }
}

The MakeSprite(), MakeSpriteWithBaseLine() and MakeButton() methods are some helper methods to simplify the code. As you can see the Start() method is where all the components of the title screen are created. Since the title screen doesn’t have any frame based animation the Update() method is empty.

Lastly HandleStartButtonRelease() is set up as the method that is called when the start button is pressed. It calls the GoToScreen() method on the Main class to switch to the GameScreen. I’ll cover this in more detail below.

Main is a subclass of MonoBehaviour and is the script that is attached to the “Futile” object in the games’s scene. It looks something like this:

public class Main : MonoBehaviour
{
    public static Main instance;
    private Screen currentScreen = null;
    private FStage stage;

    // Initialise Futile and get the ball rolling
    void Start()
    {
        instance = this;

        FutileParams fparams = new FutileParams (true, true, false, false);

        //...

        Futile.instance.Init(fparams);

        //...

        stage = Futile.stage;       

        //...       

        // and lastly show the title screen
        GoToScreen(ScreenType.TitleScreen);
    }

    public void GoToScreen(ScreenType screenType)
    {
        if (currentScreen != null && currentScreen.Type == screenType)
        {
            return; //we're already on the same page, so don't bother doing anything
        }

        Screen screenToCreate = null;

        switch (screenType)
        {
            case ScreenType.TitleScreen:
                {
                    screenToCreate = new TitleScreen ();
                    break;
                }
            case ScreenType.GameScreen:
                {
                    screenToCreate = new GameScreen ();
                    break;
                }
        }

        if (screenToCreate != null)
        {
            //destroy the old page and create a new one
            if (currentScreen != null)
            {
                stage.RemoveChild(currentScreen);
            }

            currentScreen = screenToCreate;
            stage.AddChild(currentScreen);
            currentScreen.Start();
        }

    }

    // This is called by unity every frame
    void Update()
    {
        // check if back key was pressed
        if (Input.GetKeyDown(KeyCode.Escape))
        {           
            switch (currentScreen.Type)
            {
                case ScreenType.TitleScreen:
                    {
                        Application.Quit();
                        break;
                    }
                case ScreenType.GameScreen:
                    {
                        GoToScreen(ScreenType.TitleScreen);
                        break;
                    }
            }
        }
    }
}

The Start() method here sets up Futile, sets up a static reference to the instance of Main for easy access by the screens and lastly calls the GoToScreen(ScreenType.TitleScreen) method to get the ball rolling and show the title screen.

GoToScreen() first checks that we aren’t already on the screen that has been requested. Next up it creates an instance of new screen. If there is an existing screen it removes it from the stage (so it gets garbage collected). It then adds the new screen to the stage and calls it’s Start() method so the screen can set itself up.

One thing to note is that I currently only have the TitleScreen and GameScreen plumbed in. The switch statement will need to be expanded for the help and score screens.

Lastly the bit of code in the Update() method is there to allow the back button to work for Android. If I ever port this game to iOS I will need to add some on screen buttons to achieve the same thing.

Here is a clip of this all in action:

YouTube Preview Image

 

The next post in this series can be found here

Word War III – Dev Diary – 02: Word Smithing

So I need to find some words, more importantly I need a list of words that gradually gets more and more difficult to guess.

So what makes a word hard to guess? Doing some research on the web turns up a couple of interesting posts such as this one and this one.

It turns out that short words are harder to guess, especially ones that have “non-obvious” letters. Thus words such as “jazz”, “jug”, “by” and “gym” are much harder to guess then words such as “deployments”, “historical” or “compartmentalised”.

The list of words I have decided to use scores each word based on the relative frequencies of letters in the English language.

So “jazz” scores: j(0.153) + a(8.167) + z(0.074) = 8.394.

Whereas “deployments” scores: d(4.253) + e(12.702) + p(1.929) + l(4.025) + o(7.507) + y(1.974) + m(2.406) + n(6.749) + t(9.056) + s(6.327) = 56.928.

Lower scores indicate words that are harder to guess when you have a limited number of turns.

Letter frequency for the English language – source Wikipedia

As the blog post points out this algorithm is not perfect “cup” scores 7.469 but “gym” scores 6.396. The reality is that if “_y_” is guessed ( players often work through the vowels and then onto “Y”) there isn’t a lot of options but “gym”. However if you guess “_u_” there is quite a lot of options besides “cup”. So actually “cup” should be a harder word to guess then “gym”.

However for my purposes this list will do very nicely. Unfortunately it’s 173528 words long which is a wee bit bigger then I need :) Also my design only allows me to display words with a length of 10 characters or less so I need to cull words longer then 10 characters as well.

Enter the pig

Apache Pig is something that I have used in the past when working with “Big Data” datasets. The word list isn’t exactly Big Data but Pig will happily suit my word list mangling needs.

First off I only want words that are between 2 and 10 characters. Next I only want a sample of the 173528 words. Lastly I want the list sorted from easiest to hardest. Here is my script:

allWords = LOAD 'allscores.txt' USING PigStorage() AS (word:chararray, junk, score:float);
lessThen10 = FILTER allWords BY SIZE(word) <= 10 AND SIZE(word) > 1;
shortList = SAMPLE lessThen10 0.02;

groupAll = GROUP shortList ALL;
wordsWithMaxScore = FOREACH groupAll GENERATE FLATTEN(shortList), MAX(shortList.score) AS maxScore;

wordsWithRatio = FOREACH wordsWithMaxScore GENERATE shortList::word AS word,shortList::score AS score,
                 maxScore, (shortList::score/maxScore) AS ratio;

ordered = ORDER wordsWithRatio BY ratio DESC;
justWords = FOREACH ordered GENERATE word;

STORE ordered INTO 'wordsAndScores' USING PigStorage();
STORE justWords INTO 'words' USING PigStorage();

This produces two files, one with the words, their scores and a calculated ratio (0 to 10) based on the words score vs the maximum score in the sample list of words (wordsAndScores):

tendrilous 66.33   66.33   1.0
breathings  65.555  66.33   0.988316
rediscount  65.087  66.33   0.9812603
inoculated  64.965  66.33   0.979421
atrophies   64.735  66.33   0.9759535
stewarding  64.582  66.33   0.9736469
tailenders  64.232  66.33   0.96837026
nonethical  64.048  66.33   0.9655962
authorized  63.564  66.33   0.9582994
destroying  63.537  66.33   0.9578923

The second file (words) contains just the words:

tendrilous
breathings
rediscount
inoculated
atrophies
stewarding
tailenders
nonethical
authorized
destroying

Each file contains 2477 words sampled out of the original list of 173k words.

I was initial going to use the ratio to group blocks of similar difficulty words together but have abandoned this idea. The plan is now to simply step through the list in random increments which will have the effect of gradually increasing the difficulty of the words during a game but not result into too many words repeating between games.

One problem with the list is that it contains words that are not in common usage for example “tendrilous” (adjective for “tendril”, a specialized threadlike leaf or stem that attaches climbing plants to a support by twining or adhering) and “kohlrabies” (plural of “kohlrabi”, A cabbage of a variety with an edible turnip like swollen stem). So I will need to manually groom the list at some stage :)

Loading the word list

Loading the word list in Unity is pretty straight forward. Firstly I copy the file into my project’s resource folder and name it words.txt, next I use the following code to load the words into a string list:

List words;

void LoadWordList()
{
    words = new List ();
    StringReader reader = null;

    TextAsset words = (TextAsset)Resources.Load("words", typeof(TextAsset));

    reader = new StringReader (words.text);
    if (reader == null)
    {
        Debug.Log("words.txt not found or not readable");
    } else
    {
        string txt;

        // Read each line from the file
        while ((txt = reader.ReadLine()) != null)
        {
            words.Add(txt);
        }
    }

    Debug.Log("Loaded " + words.Count + " words");
}

With the word list in place, I think I will next focus on getting the game’s screen flows sorted. Onwards and upwards!

_Update: _Click here for the next post in this series

Word War III – Dev Diary – 01: Getting started

So I’ve decided to knuckle down and build AND actually release a game. I read somewhere (probably Reddit) that publishing a development diary really helps on the motivation front. It sounds like a good idea so here we are :-)

Some constraints

First off to narrow my focus I have decided that:

  • I will make a 2D game. My 3D modeling is OK but it takes a loooong time.
  • My target is a mobile app. So distribution is taken care off.
  • Android is my initial platform: I already have test devices and dev platforms
  • I’m going to use the Unity3D platform. I bought the Android and iOS platform licenses a while back so I should really use them. Also its a very nice cross-platform tool.

Time

Nothing kills a side project like the distractions of everyday life. Luckily Mrs Gremlin suggested a few weeks ago that I earmark Monday nights for doing some game development. I’m taking her up on her offer. My wife is the best!

but Unity isn’t 2D…

No it isn’t but it handles lots of polygons which when textured and put on a plane equals lots of GPU accelerated sprites.

After digging around I found Futile. It’s new, has zero documentation but the intro videos and sample code looked good.

YouTube Preview Image

 

The developer also set up a Futile sub-reddit and he is very active on it. So I decided to give it a go.

I knocked together a shell of a space invader game using these neat graphics. Futile appears to do exactly what it says on the tin and it seems intuitive to use. Here is a short clip of my test project:

YouTube Preview Image

 

The pitch

Ok now for the elevator pitch:

The game is hangman with a time limit rather then guess limit. When a player guesses a word they are presented with a new one. The words the player gets to guess get progressively harder as the game goes one. The game has a time limit of 120 seconds with a progress bar incrementing towards game over every second. Each correct letter guess reduces the bar by 2 seconds. Each failed guess adds 1 second. Completing a word knocks off 10 seconds.

The game has a nuclear armageddon theme. The progress bar is broken up into DEFCON levels 5 to 1. The game is named “Word War III”.

Kick off

First up I sketched out some screen flows and layout ideas. Things like high score tables etc can come later:

Mrs Gremlin offered to build a title page for me (using Illustrator) and I knocked up the game page to test out the layout of the letter keys. I’m normally create game graphics using Inkscape which is vector based, this allows graphics to be easily scaled and resized as things develop. Here is the title page and the game page layout test:

The fonts are Passion One and Hand of Sean. Unfortunately it looks like the license for Hand of Sean has recently changed and it is no longer free so I’ll need to find a replacement for it.

Using BMFont I created some font atlases and then used TexturePacker (I bought the Pro version) to pack all the assets into the following atlas:

One issue I had is that I failed to export the font images as 32bit images. This caused all sorts of weirdness when TexturePacker created the atlas.

Also Futile spat the dummy when tring to load the smaller of the font sets. Some array index out of bounds error that I haven’t had time to track down.

Next I got down to some actual coding using the FSprite, FLabel and FButton classes I created the game screen. Testing on a actually device showed that my buttons were too small. Mrs Gremlin also pointed out that the keys should laid out in a QWERTY fashion. Some more tweaking and I ended up with this:

YouTube Preview Image

Not a bad start for a few hours of work.

Update: Click here for the next post in this series

Tutorial: Creating your first Unity Android App

This tutorial is out of date. See here for an updated tutorial covering the latest version of Unity.

This is a quick, step by step guide to creating a simple spinning cube app for Android using Unity. This tutorial is for windows but other then the install instructions it should work for other platforms. By the end of this tutorial you will have created an app that displays a red spinning cube on a blue background on your Android device.

Setup Unity

You will need Unity AND the Android feature to create the app. Unity basic is free and the Android feature is currently free till the 8th April 2012 (which saves you $400). Download the installer from here and get your license from here.

Install Unity and register it using your license key which should have been emailed to you.

Setup the Android SDK

To create an Android app you need to install the Android SDK, which can be downloaded from here. I have the SDK installed to c:\android-sdk-windows

Once the SDK is installed you need to add the Android 2.1 (API level 7) package. Run the SDK Manager and use it to download the API level 7 packages. See here for more info.

Lastly, you will need to install the USB device drivers for your Android device. Whilst it is possible to use the Android Emulator its performance is pretty bad (especially when emulating tablets) so you are much better off testing on a real device. If you are using a “Nexus” device you can install USB drivers using the SDK Manager, otherwise search the web for your devices drivers.

To test that everything is set up, plugin in your device, open a cmd prompt and run the following commands :

cd \android-sdk-windows\platform-tools
adb devices

Your plugged in device should be listed. You may have to enable USB debugging for your device. Go to Settings -> Applications -> Development and turn on USB debugging.

Creating the app

Start Unity and select File -> New Project to create a new project, name the project RedCube.

In the drop-down box in the upper right of the screen make sure 4 Split is selected.

Create the cube

From the GameObject menu select Create Other and then select Cube. Make sure that Cube is selected in the Hierarchy panel (3rd panel along the top of the screen), then in the Inspector panel (far right panel) set the following values for the cube:

  • Position: x = 0, y = 0, z = 0
  • Rotation: x = 0, y = 45, z = 45
  • Scale: x = 2, y = 2, z = 2

Position the camera

Select the Main Camera  in the Hierarchy panel and set the following properties for the camera in the Inspector panel:

  • Position: x = 0, y = 0, z = -5

Add a light

From the GameObject menu, select _Create Other _and then Point light. Set the following properties for the light:

  • Position: x = 0, y = 0, z = -5

Test the scene

Click on the Play button (top center of the screen). You should now see the lower left panel switch to the Game tab and you should see a white cube on a blue background.

Press the Play button again to stop the game.

Note this important! Unity allows you to make changes whilst the game is running but these changes are lost as soon as you stop the game running. This is great for debugging but is an easy way to lose you changes :)

Save your project

Speaking of losing your work, now is a good time to save your project. Select File -> Save Scene, enter RedCubeScene as the name for the scene when prompted. Then select File -> Save Project to save the project. Remember to save your work regularly.

Making the cube red

Right click in the Project panel (3rd along the bottom) and then select Create -> Material, name it RedMat. In the Inspector window click on the white color block next to Main Color and then select a red color from the color picker. Drag the RedMat material from the Project window onto Cube  in the Hierarchy window. The cube should now turn red in the various scene windows.

Making the cube spin

In Unity scripts are used to add behavious to objects and to create the logic of your game. We will use a script to make the cube spin.

Right click in the Project panel and select Create -> C# Script, name it Spin.

In the Inspector window click the Open button, give it a moment for the MonoDevelop IDE to launch. You should see a code editor window. Modify the code to read as follows:

using UnityEngine;
using System.Collections;

public class Spin : MonoBehaviour {
    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {
        // rotate at 90 degrees per second
        transform.Rotate(Vector3.up * Time.deltaTime*90);
    }
}

Save the code (press Ctrl+S) and then switch back to the Unity editor.

Drag the Spin script from the Project window on to Cube in the Hierachy window.

Press the Play button. You should now see a red cube spinning in the Game window. Press Play again to stop the game.

Building the app

Now that we have the app completed, we need to build it.

Select Edit -> Project Settings -> Player

In the Inspector window under the Per-Platform Settings click on the tab with the Android icon (3rd tab along).

In the Other Settings section change the following values:

  • Bundle Identifier = com.rabidgremlin.tut.redcube
  • Minimum API Level = Android 2.1 ‘Eclair’ (API Level 7)

Now, select File -> Preferences and then select the External Tools section. Click on the button next to Android SDK location and select the root folder of your Android SDK install (c:\android-sdk-windows in my case).

Next plug-in your device.

Now, select File -> Build & Run, this will open the Build Settings window. Select  Android under platform and then click on the Build & Run button, when prompted for a name for the .apk file enter in RedCube.

A build dialog will pop up and you will see the app being built, then you will see a message about the app getting pushed to your device.

Have a look at your device, you should see the RedCube app starting up, followed by a red cube spinning on a blue background.

Congratulations you have created your first Unity Android app !

What next?

First off go and complete the 3D platform game tutorial. This will give you a good understanding of how Unity works. Also check out the very comprehensive documentation and the very helpful community.

Now go nuts :)

Update: If you are interested in creating 2D games with Unity check out my Dev Diary for my game Word War III

Ask Gremlin…

I’ve received a couple of interesting emails recently from people asking for advice. I figured my answers might be of use to others so here are the (redacted) emails:

Android App

The email:

I am wanting a Android Application designed for me. I am wanting to know a little more about Android Applications and how to go about getting one designed for me. How do the laws work around making a app and around how much would someone have to pay to get one designed? If a Android developer was to make a app for me would the rights of that app be mine or the creator? Sorry for the inconvenience I’m really new to this. Any information would be appreciated.

My response:

Hi ****,

A few years ago there was a move in NZ to better clarify ownership of intellectual property and copyright for “commissioned works” which includes software developement. However this amendment did not pass see: http://www.med.govt.nz/templates/ContentTopicSummary____18836.aspx

Although there are some existing laws that cover this area, what you want to ensure is that there is a clause in any contracts you sign (and you should ensure you have a contract with anyone who is written apps for you) that you own ALL the IP and copyrights on the work that is produced.

In terms of how much will it cost, the answer is it depends on how complicated the app is :)

Basically there are two general models followed for software development: “Time and Materials” (T&M)  or Fixed Price.

With T&M you generally pay the developer an hourly rate. For software development you can pay anything from $25/hr through to $150/hr. Typically the more senior or skilled the person, the higher their rates. Of course paying more doesn’t guarantee quality or success.

With Fixed price the price is determined ahead of time and that is the amount you will pay for the completed software. Whilst this seems a “safe” option, software development is often complicated and unexpected things turn up all the time, as such Fixed Priced contracts are often padded with a “contingency” to ensure that the developer makes money. If the project looks risky the contingency can be as high as 50% which means you would be paying far more for the work then it is worth. The other issue with fixed price contracts is that they often have a “change request” (CR) process which allows the developer to make additional charges for work (eg features of the app) that were not covered by the original specification (or “scope”) of the project. CR processes are often confusing & abused and you land up paying way more then you intended to in the end.

The best way to “protect” yourself against unforeseen costs is to be very, very, very clear on what you want to have built. In software development this is often called “scope” or the specifications of the project.

For an Android app I would suggest that you create what is called a wireframe or mockup of the app. You can use a tool such as http://balsamiq.com/ or http://yeblon.com/androidmockup/ or even paper & pen and sketch out each of the screens of the app, add notes about what each screen should do and how you navigate from one screen to another.

Once you have your wireframe sorted you can then shop around and get different quotes from different developers to find a price and developer you like. If you think your idea is particularly unique, you might want people to sign a non-disclosure  aggreement (NDA) before you show them your wireframes or talk to them about the app.

Lastly you might want to try and write the software yourself ! Have a look at http://appinventor.googlelabs.com/about/ as a “gently” intro to Android development. It will let you create a working prototype that you can actually run on your phone :)

Hopefully the above has been helpful.

Cheers

QR code generation

The email:

I saw your comment on the hack-a-day QRcode post.  You seem to have quite a bit of experience in QRcodes and other scanning apps.  One thing that I have been looking for (and maybe you might be able to help) is a program that creates unique QRcodes from list of URLs.  I’m helping out a non-profit **\* with their website and I was trying to find an easy solution to automatically create printable QRcodes for all of the ***\** at once.  This way each **** has their own QR code to an info page on a WordPress blog.  It could be done manually, but the ** change every two weeks! :)

A bonus would be automatically taking Bitly URLs and turning them into a bunch of printable QRcodes.

Just thinking

My response

Hi *****,

The Google Charts API can be used to quickly create QR codes. Check out: http://code.google.com/apis/chart/infographics/docs/overview.html and http://code.google.com/apis/chart/infographics/docs/qr_codes.html

So the following #aliases: https://chart.googleapis.com/chart?chs=150×150&cht=qr&chl=http://blog.rabidgremlin.com  would create a 150px by 150px .png QR code containing a URL to my blog (http://blog.rabidgremlin.com)

You could probably use a tool such as Curl or WGET to script the fetching of the bar codes.

Cheers

Android Tips: Using a live wallpaper as your app’s background

This one took a while to find so it’s worthy of a tip :)

To use the current live wallpaper as your app’s background, simply set the theme for your activity to @android:style/Theme.Wallpaper in your AndroidManifest.xml:

...
<activity .... android:theme="@android:style/Theme.Wallpaper">
 ...
</activity>

What I did last week – 15 Feb 2011

Actually it’s more what I did last month.

RC simulator

A mate of mine bought himself a swish RC quad-copter. As part of the package he bought Phoenix RC. It is a simulator that allows you to plug your RC controller into a PC and you can then practice flying (and crashing) virtual RC models before tackling the real ones. Very useful and it clearly proved that I should never attempt to fly a real RC helicopter.

Kinect

Believe it or not, I’m actually getting paid to hack a Kinect. Im using the OpenNI framework so hacking really consists of installing the software and then using a nice high-level framework that does all the hard work for you. I’ve been very impressed with the skeleton tracking.  I’ve been able to simultaneously track 3 people with full skeletons without any issues.  This is the guide I used to install the base software. You should also check out the Ogre and Unity demos.

Unity

Whilst tinkering with the Kinect I ran through the Unity 3D platformer tutorial. Unity is very impressive. If you want to create a 3d game I’d start here.  The basic version is free. The cross platform nature of the engine is impressive to.

Auckland Buses app

I finally got around to releasing my Auckland Buses app for Android. It only took a few hours to put together.  I’m experimenting with an ad supported model. The app has about 225 users, averages around 25 impressions a day. So far I’ve made 49c so not really a money maker :) What is interesting is the fairly poor fill rates I get some days.  If you had marketing dollars to spend,  mobile ads might be the way to go as not many people seem to be tapping them.

That’s about it…