Nicholas Nicholas - 2 months ago 19
Android Question

Integration of Unity and Eclipse

Hey guys I need a little bit of help with integration of Unity into Eclipse

My reference page is this => here

I have Unity3D Pro version and Android Plugin Pro Version

  • Set up your Unity Android project as you would normally and hit

  • Enter your project folder, go to Temp/StagingArea.

  • Copy all project files to a new folder.

  • Import this folder as a new Android project in Eclipse.

  • Mark this project as a library in the properties window for the
    project. (Right click on the project name, go to Properties->Android
    and mark "Is Library".)

  • Create a new Android project in Eclipse. This will constitute the
    Java part of your project.

  • Add the Unity Android project as a library to your new project.
    (Right click on the project name, go to Properties->Android, select
    "Add...", add the project.)

  • Add the classes.jar library to the Library references for your new
    project. (In properties, go to Java_Build_path->Libraries, select
    "Add External Jar...", navigate to
    UNITY_INSTALLATION\Editor\Data\PlaybackEngines\and roidplayer\bin and
    add classes.jar)

By now, If I am running this little project into my device I get something like this

You can see the picture from this link.

The next Step is this:

  • Move the assets folder from the library project to the new project.
    (Android does not allow assets to be utilized in libraries, and this
    last step has to be repeated whenever the Unity project is rebuilt.)

I am moving the asset folder and the res folder from the library project to the new project.

After that I am moving the AndroidMnifest.xml from the library and replacing in the project

This is my Code from

package com.Developer.PackMan;

import com.unity3d.player.UnityPlayerNativeActivity;

import android.os.Bundle;

public class MainActivity extends UnityPlayerNativeActivity {

protected void onCreate(Bundle savedInstanceState) {


And this is Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="" package="com.Developer.PackMan" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name" android:screenOrientation="landscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.sensor.accelerometer" />

After I am building it i got an error with the following text

The application )process com.Developer.Packman) has stopped unexpectedly please try again.

The problem is that I am not getting any kind of Errors in LogCat or Console, everything is clear.

I really need your help. Thank you.


For an app which has to show both Unity3d and regular Android UI, I wrote a guide for my future use. AFAIR it's based on Unity3d version 4.3. I hope it's detailed enough :)

Based on links:


In order to start integrating Unity3d and Android you need the classes.jar file found in '...Unity\Editor\Data\PlaybackEngines\androidplayer\bin'. You can place it in your workspace directory.


  1. Start with an Android project which will contain all the Android bits.
  2. Prepare the Unity3d Android project. Import the Unity project into your workspace like a regular Android project.
  3. RMB on the Unity project, click “Properties”, then go to “Android” and tick the “Is Library?” check box.
  4. RMB on the Android project, click “Properties”, then go to “Android” and click “Add” to add a library - the Unity project - to the Android one.
  5. Still in the “Properties” dialog, go to “Java Build Path” and select the “Libraries” tab. There, click “Add external JAR” and navigate to the classes.jar file.
  6. Ensure both projects target the same SDK.
  7. Move the “assets” folder from the Unity project into the Android project. This step has to be repeated each time your Unity project is rebuilt.


This guide assumes your goal is to have an Android activity which will display both a Unity model and regular Android UI.

  1. Add the following line to the base of the project’s manifest file: ‘’.
  2. Add the following line in the manifest to the activity which is supposed to contain the Unity model: ‘’. This enables touch events to be passed to both Unity models and regular Android UI.
  3. Make the activity extend UnityPlayerActivity rather than Activity.
  4. Don’t add the ‘setContentView’ straight in onCreate() - this leads to unwanted behaviour - in my case the Unity model was very small and couldn’t be interacted with; instead, in onResume() find the parent view of the UnityPlayer object and in it inflate the layout and add all the other UI elements. Note that it’s possible that finding of said view might need to be done in a separate thread.


  • NoClassDefFoundException (or similar) on classes which extend UnityPlayerActivity: go to Properties of your Android project, then Java Build Path -> Order and Export and tick classes.jar (in my case it was at the top of the list if that makes any difference). Press OK, clean the project, try to run again and PRAY…
  • multiple dex files define Lcom/unity3d/player/nativeloader - make sure the “libs” dir in the Unity project does NOT contain the “unity-classes.jar” file.
  • (Not sure but worth a try) problems in the src folder - remove the contents of the src folder

Here's some sample code to illustrate the Activity which holds the Unity3d object:

private Button buttonChangeColour;
private UnityPlayer unityPlayer = null;

public void onResume() {


    if (unityPlayer == null) {

        View rootView = findViewById(;
        unityPlayer = findUnityPlayerView(rootView);

        if (unityPlayer != null) {

            ViewGroup unityPlayerParentView = (ViewGroup)(unityPlayer.getParent());
            View mainHomeView = getLayoutInflater().inflate(R.layout.activity_home, null);
            LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            unityPlayerParentView.addView(mainHomeView, layoutParams);

            buttonChangeColour = (Button) findViewById(;
            buttonChangeColour.setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {
                    // [...]

private UnityPlayer findUnityPlayerView(View view) {

    if (view instanceof UnityPlayer) {

        return (UnityPlayer) view;
    if (view instanceof ViewGroup) {

        ViewGroup childrenViews = (ViewGroup) view;

        for (int i = 0; i < childrenViews.getChildCount(); i++) {

            UnityPlayer foundView = findUnityPlayerView(childrenViews.getChildAt(i));

            if (foundView != null) {

                return foundView;

    return null;