How to integrate your Unity Program to Android Studio

Unity

This last couple days, I try to integrate my program in unity with android studio. I am not an expert in both platform but I try to learn it for my class project. To be honest, I have experience working with android studio, for me it is a really good tool to build your android apps, however if you want to develop a games app, it will be little difficult working in this platform. That is why, I try to work with unity, but this is really unfamiliar environment for me, so to make my project can be done, I try to combine both this two tools.

I don`t know this is a stupid idea or not, but maybe some of you want to use this method, then I will help you.

1. Install both android studio and unity in your PC (Don`t worry both are free)

2. Build your apps in both platforms, in my case I build spotify like program in android studio and the game apps in unity.

3. If you done with the design in both platforms. Go to unity and go to Edit -> Preferences ->External Tools. You must locate the SDK and JDK location in your computer. If you don´t know the location of SDK, just open your android studio and click SDK manager button, and new windows will open, and see SDK android location in that windows.

Unity
The Preferences window in Unity, to Locate your SDK and JDK

For JDK, if you don´t have one, just download it in and choose the new java development kit provide by oracle, after that just install it in your laptop and don´t forget to remember the location of that file.

4. After you located both those file, right know you able to build your android program from unity. To make sure you can combine your unity program with android studio, copy your android manifest.xml file from android studio than in unity in assets folder make new folder name plugins, and inside plugins make new folder name android. After that paste the manifest.xml in this folder.

Unity
Copy your android manifest.xml file to unity after make this folder

5. if you already copied the manifest.xml, then in unity go to file -> build settings. In platform choose android, and choose this settings.

Go to build settings to create your android studio project from unity

6. After that you will get new file that have same type with android studio. Open that file you already build from unity in android studio.

android studio
Gradle have finished the build, move the files from your android studio project that you want to combine to this file

7. After open the unity file in android studio it will build gradle. Then the gradle build finish, move the java and res file from your android studio project you want to combine with unity. Because you already copied the manifest file so, in this unity project android studio will follow that manifest file. If there is no folder like raw, or drawable in unity android studio, just crate one.

8. Don`t forget to change the package name in your java folder, it must follow the unity package name, you can see the example in UnityPlayerActivity.java file

Don`t forget change the package name from your previous java file to unity android studio project.

9. Don`t forget to create button and intent that will open this file UnityPlayerActivity.java, to go to Unity layout game

android studio
Create button and intent to move to Unity game

10 At the end, go to manifest.xml in unity android studio project. And put UnityPlayerActivity.java activity in that mainfest or copy this script below, with some change in android:name part Then build your program in Android studio

<activity android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" 
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" 
android:name="com.wawan.SpotifyGame.UnityPlayerActivity">
  <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
android studio
Copy that part to android manifest in unity project, change the name name part

After that just build the file in android studio.

The result below:

 

 


 

(Visited 1,985 times, 8 visits today)

4 thoughts on “How to integrate your Unity Program to Android Studio

  1. Hello, great tutorial! it’s works so well.
    but i have a question
    i added a c# script file that animate my object in the unity project
    how can i found it in the android project after i exported ?
    because i want to modify the update method according to input from a serialport.

    1. hello good questions, i am sorry cause i got this problem too, when i updated the unity code i need to built again the code from unitz and imported to android studio. i can not find the way how to insert c# file into android studio, because usually when you build the file from unity into android, it will convert all c# file into java, and it will be hard to convert c# into java bz our own.

      1. thank you for your reply, so how can i find these java files in the andoid project? and do you know how to move the object that i created by unity in the andoid?
        thank you so much

        1. The java files for unity you can see it in java folder and the file name usually is “unityplayeractivity” and if you want to move or add java file into your project, I usually build the unity first then convert it to android studio project then in this android studio project that have been converted from unity, I put all my java code like menu or other activity in those project. And don’t forget to edit the android manifest if you have done adding file.

          I hope this answer your question

Leave a Reply