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
Create a unity project using android pro.
- Open unity . go to File-> build settings in Unity and create a build for project.
- go to your-project-location/temp/.
- There is a folder named Staging area.
- Copy this folder to other location. rename this folder. eg test-unity.
- Now go to eclipse create a new project from existing code. go to test-unity and select it. New project is created.
- Right click on project and select properties.
- select android from left tab list. and check is library on right panel. apply the changes.
- Now create new project in android name it test-android.
- The package name has to be the same as you have used in unity.
- 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.
- Now copy the assets folder form unity project to in eclipse to test android project.
- Also copy libs->armeabi-v7a to libs folder in unity.
- 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.
- Now open main activity.class in test-android project and paste this line
import com.unity3d.player.UnityPlayerActivity;
- Now replace Activity with UnityPlayerActivity as below
public class MainActivity extends UnityPlayerActivity
- comment the line setContentview(R.layout.main).
- Now run your app.