Unity 2D Prototype part 5 – Deploy to Android

      Comments Off on Unity 2D Prototype part 5 – Deploy to Android

Now that we’ve got a technically complete game, that is, gameplay with the ability to complete the game and start over without restarting the application, let’s push the application to a device and see how it works on an actual touch interface. Go to edit -> project settings -> Player. Under the other settings section the Bundle Identifier needs to be changed to be unique since this is the name that android will install the game under. I chose com.ChrisKugler.Prototype which follows the given format of com.<CompanyName>.<ApplicationName>

Go to file -> build settings.

Press Add Current to add the scene to the build output. When you build a game with multiple scenes they all need to be included in this stage.

Select android and hit build and choose a name for the .apk file.

Plug your android device into the usb port of your computer and copy the apk file to somewhere easily accessible like the downloads folder. Once this is done browse to the downloads folder in your preferred android file browser. I like Droid Explorer myself. Once there run the .apk file to install.

As an alternative deployment method you can use the build and run method. If your phone is connected and unity can detect that it’s connected it will automatically deploy and run your application in your device. I had a lot of trouble with this initially on my HTC one. I updated the android sdk through the SDK Manager application I had installed, and after updating several times and restarting my computer I still had issues. HTC Sync manager may have also been a requirement for me. After installing updating, unplugging and replugging my phone in, making sure my developer options on my phone had usb debugging enabled, restarting my computer, and so on it still wasn’t working. Then I tried again later in the afternoon and it magically worked…. Hopefully your time with this is easier than my own was. If you’re unable to get this process to work then you’ll have to rely on the previously stated method of manually copying the apk and running it from the device.

Once you run the program you should see this.

It looks way different than what we saw in the unity editor. Because the screen resolution and size are different than what we’ve been looking at we’ve ended up with strange UI problems. It’s easy to solve though. On each of our canvas controls is a component called Canvas Scalar. Change the scalar so that instead of constant pixel size we use Match Width or Height. This will cause the UI to scale to the device resolution and the UI positioning should move to match whatever device you run on. I went with the default resolution of 800 x 600.

When we changed the settings your canvas should look more like what we saw on the phone. From here just re-adjust the size and position of all the controls in the canvas so they’ll look good. You can also use the match slider to adjust the controls so some degree.