How to integrate Unity into an Android Activity

I figured it out. I was following these directions but kept getting various error messages including ClassNotFound exceptions.

It turns out the way that ADT 17 handles .jar files broke this method of integrating Unity into Eclipse. After hours of searching, here's the fix I came up with:

Instead of adding classes.jar to your build path, you should just copy the classes.jar file into the /lib directory of your project, and everything should work properly.


Hi Below are the steps to follow

  1. Create a unity project using android pro.

    1. Open unity . go to File-> build settings in Unity and create a build for project.
    2. go to your-project-location/temp/.
    3. There is a folder named Staging area.
    4. Copy this folder to other location. rename this folder. eg test-unity.
    5. Now go to eclipse create a new project from existing code. go to test-unity and select it. New project is created.
    6. Right click on project and select properties.
    7. select android from left tab list. and check is library on right panel. apply the changes.
    8. Now create new project in android name it test-android.
    9. The package name has to be the same as you have used in unity.
    10. Right click on project. go to android and add library. You will see the unity project name. select it. the unity project is added as library in test-android project.
    11. Now copy the assets folder form unity project to in eclipse to test android project.
    12. Also copy libs->armeabi-v7a to libs folder in unity.
    13. now go to unity installation dir. In my case( C:\Program Files (x86)\Unity\Editor\Data\PlaybackEngines\androiddevelopmentplayer\bin) . Copy classes.jar to libs folder in test-android project. optional–. After copying classes.jar if you cannot see classes.jar in android-dependencies folder of test android project go to build of test-android and include this jar file.
    14. Now open main activity.class in test-android project and paste this line

    import com.unity3d.player.UnityPlayerActivity;

    1. Now replace Activity with UnityPlayerActivity as below

    public class MainActivity extends UnityPlayerActivity

    1. comment the line setContentview(R.layout.main).
    2. Now run your app.