nickey 2011-12-02
Once you have eclipse installed and up to date you have to follow a few steps to get your unity project set up as a library in eclipse.
This completes the steps that you need to carry out to have your unity project addressed as a library in eclipse.
The next step is to create the eclipse project that will form the executable part of the project.
This sets up a basic Java Project that is now linked to your unity project and the relevant libraries that we will later need.
This is the important part to get your unity content into the Java Project so that it will display when you later build and run your Java Project. You now need to move all the files in the assets folder in the library project into the new project. This is because Android does not allow assets to be used in libraries. The best way to do this is from within the Eclipse IDE. If you expand the assets files within both parts of the package explorer and simply drag the bin and libs folders from the library part of your project to the other. This last step needs to repeated everytime your unity project is rebuilt or maybe you could write a script to handle moving the files everytime you build the project automatically. This could also be achieved using symlinks or junctions. At this point when you run the from the eclipse ide you will be asked which type of project that you want to run. Select android and click ok. After eclipse builds the project it will deploy it to your connected android device and you should see a hello world style application running.
To get your unity project you need to make a few changes to the java source code. In your eclipse project there will be one source file (.java) open this file. The contents of this file will resemble something like this.
package com.Unity3D.EclipseIntegration; import android.app.Activity; import android.os.Bundle; public class EclipseIntegration extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
We need to change this. The first thing is to change the base class of the object. It should now instead extend UnityPlayerActivity. You will notice that when you do this that it is red underlined proclaiming errors. This is simply missing import directives in the file. The eclipse shortcut to auto resolve this is ctrl+shift+o. The fiel should now have the import statement.
import com.unity3d.player.UnityPlayerActivity;
If you run in this state you will see that you now have a full screen hello world application. This is not what you want we need one more change to get your unity content running.
In the onCreate function there is one line that is overriding the unity view in the android application. If you delete the line.
setContentView(R.layout.main);
The complete file should now look like this.
package com.Unity3D.EclipseIntegration; import android.os.Bundle; import com.unity3d.player.UnityPlayerActivity; public class EclipseIntegration extends UnityPlayerActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } }
If you run it now you will see your unity content running on your android device.