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.

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.

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

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.

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

9. Don`t forget to create button and intent that will open this file UnityPlayerActivity.java, to go to Unity layout 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>

After that just build the file in android studio.
The result below:
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.
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.
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
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
I want to launch unity 3d program using a button click from android application and return back to the android activity from unity application on back button press.
How can I implement this can you help me to solve this problem ?.
probably by making a new Activity that you make your first activity. then you kan make a button and intent for the button to go to the game activity. which is the UnityplayerActivity. i haven’t tried it myself but that is my guess.
Hi
thank you for this tutorial. I have a question it may be silly but it is my problem.
in part 7 you mention that copy java and res file from android studio project to unity project, my question is does it possible in reverse?
I mean I want to copy unity stuff to my android studio project because my unity project is a simple one but my android
project has a lot of module and setups so It is necessary for me to do copy in reverse. I try to copy java and resources of unity project but there is a lot of errors because of libraries and when I copy libraries and seems to have no error my intent to unity class stop my app. so can you help me on this please?
I receive this error
E/mono: It should have been installed in the `/data/app/com.example.myweddingbaseapp-1/base.apk/assets/bin/Data/Managed/mono/4.5/mscorlib.dll’ directory.
E/CRASH: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build type ‘Release’, Scripting Backend ‘mono’, CPU ‘armeabi-v7a’
Build fingerprint: ‘samsung/ha3gxx/ha3g:5.0/LRX21V/N900XXSEBQB1:user/release-keys’
Revision: ’11’
E/CRASH: pid: 22342, tid: 22342, name: yweddingbaseapp >>> com.example.myweddingbaseapp <<<
r0 00000000 r1 beaf3540 r2 711716a8 r3 beaf3548
r4 beaf3540 r5 94dfc250 r6 beaf3548 r7 711716a8
r8 beaf34f4 r9 aeaff980 sl beaf34bf fp beaf3470
ip 94aec168 sp beaf3460 lr 94aec2c0 pc 94aebf28 cpsr 00005746
CAN i download unity game from my server and install it runtime