Exporting and running Unity3D project to Android Studio

Exporting and running Unity3D project to Android Studio is not really hard. Make sure the you have the latest version of Unity(5.4) and Android Studio(2.1.3). This steps were made with the version mentioned above.

EXPORTING TO Android Studio:

1.Create a root folder that will hold the exported folders and files. Let’s call it AndroidTestProject in this case and the full Directory will be C:/AndroidTestProject.

2.Exporting to C:/AndroidTestProject.

A.File->Build Settings…

B.Select Android on the left then tick Google Android Project checkbox.

Image Description:
enter image description here

C.Click the Export Button.

D.Select C:/AndroidTestProject then click the Select Folder Button.

Image Description:

enter image description here

Unity will build your project.

After Generating the project, a new folder will be created in the C:/AndroidTestProject directory. That folder will be named whatever your Product Name is in the Player Settings. This what my product name is in the Player Settings:

Image Description:
enter image description here

So in my case, the new Folder name will be called test and will be located at C:/AndroidTestProject/test.

IMPORTING INTO Android Studio:

1.Create a new Folder called AndroidStudio in the C:/AndroidTestProject/ directory. The full path of that folder should be C:/AndroidTestProject/AndroidStudio.

A.Open Android Studio. When you open Android Studio, click on Import project (Eclipse ADT,Gradle, etc.)

If Import project (Eclipse ADT,Gradle, etc.) is not displayed, close the current project by going to File->Close Project.

Image Description:
enter image description here

B.Go to the full directory of the exported project C:/AndroidTestProject/test then select the test folder which is the Product Name of your project then click Ok.

Image Description:
enter image description here

C.A new Window will pop up. Set the Import Destination Directory to be C:/AndroidTestProject/AndroidStudio which was created in step 1.

Image Description:
enter image description here

D.Click the Next Button.
Tick/Select the follwing check boxes:

  • Replace jars with dependencies, when possible.
  • Replace library sources with dependencies, when possible.
  • Create Gradle-style (CamelCase) module names.

then click the Finish Button.

Image Description:
enter image description here

2.Wait for Android Studio to load your project.

You will get an error that looks like this:

Error:Minimum supported Gradle version is 2.14.1. Current version is
2.10. If using the gradle wrapper, try editing the distributionUrl in C:\AndroidTestProject\AndroidStudio\gradle\wrapper\gradle-wrapper.properties
to gradle-2.14.1-all.zip Fix
Gradle wrapper and re-import project
Gradle settings

A.Simply click on the Fix Gradle wrapper and re-import project Gradle settings message. If you don’t see this message, make sure that you are in the Messages Tab. Look at the image below for more information.

Image Description:

enter image description here

B.Wait for Android Studio to finish fixing the Gradle problem.

When finished, go to Build->Make Project.

After project is done building, go to Run->Run ‘app’.

C.A new Window will pop up. You can either chose the device to run the app on, create an emulator or chose already existing emulator to run the app. In this example we will use a real device to test.

Under Connected Devices, select your device then click the OK button.

Image Description:

enter image description here

Extra:

A.If you want to be able to debug your App, you have to enable that from Unity. Go back to EXPORTING TO Android Studio step 2B and enable Development Build.Also select Script Debugging then click the Export Button.

B.If you want to see Debug.Log messages, go to the Android Monitor Tab in the Android Studio.

The circled items in the image below are important to know when Debugging in Android Studio.

Image Description:

enter image description here

This is not really hard. If you do it once, you won’t need this instruction again.

Leave a Comment