Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3D and Android Studio Integration

Anyone know integrate Android with Unity Studio? (i will explain)
I created a simple scene in Unity (4.3.x on OSX Maverics) for testing. Has a 3D object and nothing else.
I do this in XCode using the Stackoverflow explanations here and i post my complete code here ( Touch a UIButton and show Unity on UIView or UIViewController ) to show it's really simple.
But now, I need to do the same on Android Studio (which I installed and I can export the project from Unity to Android)
The only thing I know is that the AndroidManifest.xml and the file is in "res/layout/(something).xml" files that are the first (read) and (displays) the layout on the screen when you create a project on Android Studio.

When you open the generated project from Unity, the only XML you have is AndroidManifest.
So I'm lost. Since the document of third part site (http://www.rbcafe.com/Softwares/Unity/Documentation/Manual/android-GettingStarted.html) only mentions the Unity Eclipse and a JAVA files that do not exist in the project, makes me more lost.

In Objective-C, you create your somethingDelegate.mm and .h and inserts "a line of code" and ready. In Android does not seem to be as simple as this official document (http://docs.unity3d.com/Manual/PluginsForAndroid.html ) says.

Someone already did this in the Android Studio and could help me?

Thanks in advance.

** Edited for bounty: **

Need to create 3 views:
1 - Main View with 2 buttons;
2 - One button go to a second View;
3 - Other button go to Unity View;

There must be a simple way to do this on Android as a studio made ​​the link above.

like image 758
Daniel Arantes Loverde Avatar asked Jul 03 '14 22:07

Daniel Arantes Loverde


People also ask

Can you use Unity with Android Studio?

You can download Android Studio from the Android Studio website. Once you have downloaded Android Studio, you need to add the Android SDK path to Unity. See Unity documentation on Android SDK/NDK setup for steps on how to do this. Once you have your Android developer environment set up, you can open your Unity Project.

Is Unity better than Android Studio?

When assessing the two solutions, reviewers found Android Studio easier to use and do business with overall. However, reviewers preferred the ease of set up with Unity, along with administration. Reviewers felt that Android Studio meets the needs of their business better than Unity.

How do I import an Android Studio project into Unity?

In Unity open File | Build Settings... , check Google Android Project and click Export. Open Android Studio and click Import Project (Eclipse ADT, Gradle, etc.) Within the file selection dialog, navigate to the folder where you exported the project and select the folder named after your app.

Can Unity make Android apps?

Unity will start to build your app, however, before it can fully complete the build it will require the location of your Android SDK. To find this location, open up Android Studio > Configure Settings > SDK Manager then look at the top for the “Android SDK Location”. This is the location you must point Unity to.


3 Answers

Setting up an Android project is really simple. The document you linked is outdated and you don't need to move any files at all.

Unity

  1. Goto File -> Build Settings -> Android and click Switch Platform
  2. Enable Google Android Project
  3. Click Export and choose where you want the Android project to be

Android Studio

  1. Import or open the project you have just created with Unity
  2. Done :)

If you want to display the Unity engine inside a subactivity, I suggest you take a look at this answer.

If you're completely unfamiliar with Android development, you should start with a simple "Hello World" app without complicating things by adding Unity to the mix. Just follow some of the official Android guides.

like image 120
Stefan Hoffmann Avatar answered Oct 24 '22 04:10

Stefan Hoffmann


I integrated a Unity project to an Android application.

I had a simple activity with a button created using Android Studio.

On clicking this button the Unity scenes will start.

My Activity Unity Activity


The android project exported from unity should like this: enter image description here


It needed to be converted to Gradle project first.

For that:

  1. Open Android Studio -> choose import project -> select the unity project (Non-Gradle project) -> save project and close.

Now your unity project folder looks like this:

enter image description here


Now open your project and do the following to import the unity project in to your project:

  1. Click File -> New -> New Module -> Select "import Gradle Project" -> choose the unity gradle project folder you just created -> rename module name if prompted by checking the “import” checkbox in Android studio -> Click Finish
  2. Verify in Settings.gradle file to see if the new module name is added in the include command:

    include ':app', ':yournewmodulename’
    
  3. Open build.gradle file of the new unity module from navigation window and rename the below line:

    apply plugin: 'com.android.application'
    

    to

    apply plugin: 'com.android.library'
    
  4. Remove the line from the defaultConfig section of the new unity module:

    applicationId "com.xxx.xxx"
    
  5. Open Manifest of this new unity module and comment the application tag (Do not remove the uses-sdk tag).Integrate the new unity module's Manifest with your project’s Manifest by moving necessary tags to our project’s Manifest (e.g. :Activity, uses-feature etc.).

  6. Open build.gradle of your project and add below line in the dependencies section:

    dependencies {
    …
    compile project(path: ':yournewmodulename')
    
    }
    

Now on button click you can call the Activity in the unity module from your activity as below:

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.xxx.xxx.UnityPlayerActivity;

public class MainActivity extends AppCompatActivity {

private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button= (Button)findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(MainActivity.this, UnityPlayerActivity.class);
            startActivity(i);
        }
    });
}
}
like image 32
mustaq Avatar answered Oct 24 '22 02:10

mustaq


For open a Android Studio project from Unity3D inside Android studio as march 2016 you need to File -> New -> Import and let the thing do his work.

Or if you have the quick start window:

enter image description here

like image 31
tyoc213 Avatar answered Oct 24 '22 03:10

tyoc213