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.

4
  • this is extremely difficult. Did you think to google? forum.unity3d.com/threads/… stackoverflow.com/a/30623242/294884
    – Fattie
    Commented Feb 21, 2016 at 14:12
  • Possible duplicate of Android - embedding Unity3d scene in activity - need to unregister receiver?
    – Fattie
    Commented Feb 21, 2016 at 14:12
  • @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. Commented Feb 22, 2016 at 16:17
  • as a rule it's incredibly difficult to do the "unity inside android" or "unity inside ios" jobs. good luck in all events
    – Fattie
    Commented Feb 22, 2016 at 16:47

3 Answers 3

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);

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]

1
  • It prompts a message "Failure to initialize". How to initialize?
    – ARiF
    Commented Jun 22, 2017 at 9:52
-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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.