Sunday, 3 February 2013

How to Export to Android Using Unity


Here is how I was able to set up the android sdk and export from unity to my android phone. I am not sure if this is the correct way or the best way but it is how it worked for me.

Firstly you need to get yourself a pro version of unity you can either buy the expensive licences which are $1,500 for the pro version and $400 for the android license or you can get the 30 day free trial which is what I would recommend.

You can get unity by going to the unity website http://unity3d.com/unity/ and clicking on the download link in the top right corner. Once it downloads it will pop up with a choice for either a free license or a 30 day free trial for the pro version, select the pro version and make an account if you need to or log in with your email address and password.  

Next you need the android sdk which you can get from http://developer.android.com/sdk/index.html

Click on the blue button to download the ADT bundle for windows.


On the next screen agree to the terms and conditions and download the 32-bit version.  You could try 64 bit but I have heard of there being problems with using the emulator so I stuck with the 32-bit.


Once the zip folder downloads I extracted it to my C: drive.

Once you have done this if you open up the folder there should be 3 items, an eclipse folder, sdk folder and an application called SDK Manager.

If you open up the SDK Manager application it will have a list of all the different versions of android and two folders one called tools and one called Extras. You want to open up the extras folder and make sure that the Google USB Driver is installed as you may need this driver to use your phone properly.

Before you plug your phone in you need to enable USB debugging inside the developer options which can be found within the settings on your phone.

If you now plug in your android phone, it should automatically install the drivers for you and your phone should be recognised as an Android device in the device manager. If not you will need to install the Google usb driver that we just downloaded.

You can install the driver to your phone by selecting your phone in the device manager.
In my case my phone was under the portable devices.


If you right click and open up the properties and then go to drivers and then update driver and select “browse my computer for driver software” and find the following folder.

And hit next the driver should be installed and your phone should be recognised as an android device. If not then I’m sorry you are on your own I don’t know how to fix that L.

Once this is set up we should be able to make a new unity project which can be exported to the phone.

I am assuming you know how to do some basic things in unity, like make a new project, add objects and scripts to the project etc.

First thing to do is to make a new project in unity which we will use to export to our phone.

Inside this new project let’s add a cube and a plane and we will move the cube about using the accelerometers. 

So once you have added the cube and plane and a directional light you should have something that looks like this.

 Once you have this add a new c# script called MovableObject and input the following code


 Drag this script onto the cube object so that it is attached. This will allow us to move an object using the accelerometers.

Next we need to set up unity to get it ready to export to the phone. To do this we need to go to Edit->Project Settings->Player and you should be presented with the following screen.




You want to select the little android icon and set the default orientation to landscape left. And then select the Other Settings option lower down the page.



Here we need to make sure that the company name and product name match up with the bundle identifier. It should be com.CompanyName.ProductName so we need to change that to match the company name and product name we have chosen. This step is important or else it will crash when you try and export.

After this we are almost ready to build and run. We just need to set up the build settings.

To do this goto file->Build Settings


Here you need to select android and then add current to add the scene that we want to export to the build. Once you have done this your screen should look the same as the one above and we should be able to hit build and run!

Save the file anywhere you would like and name it whatever you want, Remember your phone needs to be plugged in.

The first time you run, unity will ask for the location of the android sdk, here find the folder that we downloaded earlier the one called adt-bundle-windows-x86_64 and select that.

It will come up saying it is building the scene and pushing to the device.



Unity should open up on your phone and there should be a cube which you can move about the screen by tilting the phone!

I hope this was helpful for you and made sense  it was done in a bit of a rush but if you have any questions email me at 10004794@napier.ac.uk and I will see if I can help.

3 comments:

  1. followed step by step but when selecting the location of the sdk and selecting the folder you suggest the window flashes and reverts location to default "android-sdk-windows" ... probably doing something stupid but anyway, thank you for the help

    ReplyDelete
  2. hay frinds i see your tutorial is good but me my unity is not export see : Error building Player: Win32Exception: ApplicationName='/Users/m/Desktop/dosier/android-sdk-macosx/platforms/android-14/aapt', CommandLine='package -v -f -m -J gen -M AndroidManifest.xml -S "res" -I "/Users/m/Desktop/dosier/android-sdk-macosx/platforms/android-14/android.jar" -F bin/resources.ap_', CurrentDirectory='Temp/StagingArea'


    send me the sdk or intent for fixe the problem

    ReplyDelete