How to import unity project into existing Android studios projecT?
Asked Answered
W

3

2

I am having problems importing unity project into Android Studios. I already have a Android studio project (for menu and other things), and i want to add a scene from Unity 5 3D, as a second activity (not the main activity).

I want to call unity scene when user clicks the button.

I know how to export it from unity but it automatically sets it as MainActivity, and i cant find a way to manually overwrite it.

Edit: I want to do it in Android Studios and not Eclipse. I just want to know if there is an easy way to do it, or at least a hint for how to do it.

Wivinah answered 21/2, 2016 at 11:8 Comment(4)
this is extremely difficult. Did you think to google? forum.unity3d.com/threads/… https://mcmap.net/q/296568/-android-embedding-unity3d-scene-in-activity-need-to-unregister-receiverPostulate
Possible duplicate of Android - embedding Unity3d scene in activity - need to unregister receiver?Postulate
@JoeBlow , thanks for the links, but both the links are for eclipse, and as I wrote, i want to do it in Android studios (i have tagged it). I did google it but couldn't find it (you know google doesn't give the right answers always). And if its really hard i might switch to unity, but i just wanted to know if the is a easy way to do it, since android studios is a lot different than eclipse.Wivinah
as a rule it's incredibly difficult to do the "unity inside android" or "unity inside ios" jobs. good luck in all eventsPostulate
B
6

Had the same requirement and successfully imported the Unity project into an existing Android Studio project. As mentioned the first thing will be to export the Unity project. I used Unity version 2017.1. Rough steps below:

  1. Export Android project via Unity build settings

enter image description here

  1. You can simply select the folder where your existing project is located. Unity should add a sub folder with an Android Studio format project and all dependencies and everything it needs to run.

  2. Now we need to convert this "Application" project to a "Library" project. This is simply done by changing the build.gradle file. Replace apply plugin: 'com.android.application' with apply plugin: 'com.android.library'.

You also need to remove the applicationId and change the compile versions to match your project's versions.

  1. Also make sure to modify the Unity module AndroidManifest.xml file. You will need to remove the LAUNCHER intent-filter as the UnityPlayerActivity will not be the main activity anymore.

    android.intent.action.MAIN

    android.intent.category.LAUNCHER

Also need to remove the Application node attributes so it won't conflict with your project's manifest.

  1. Finally in your settings.gradle add the module and then add the Unity project dependency on your "app" module: compile project(':UnityFolder')

  2. Build and now you should be able to start the Unity Scene by calling:

    Intent intent = new Intent(this, UnityPlayerActivity.class);

    startActivity(intent);

Bussell answered 11/8, 2017 at 3:43 Comment(0)
F
0

yes we can start another activity before unity Activity 1 step-create java class and add it in manifest and like in image

2nd step- create onClick in java class link to unity game class s you can see in amage see pic, you can choose button also

3rd step- in manifest replace Intent in own java class it will work [3]

Fabio answered 3/8, 2016 at 9:24 Comment(1)
It prompts a message "Failure to initialize". How to initialize?Superabound
S
-5

From this link: https://nevzatarman.com/2015/01/04/unity-android-tutorial-opening-unity-scene-from-an-activity/

Add android:process=":UnityKillsMe" to the unity activity GameActivity.

Sealer answered 24/4, 2017 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.