Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Unity with Eclipse - How to follow the "official" tutorial's instructions?

I have read all the documentation I found on how to integrate Unity3D projects targeted to Android into eclipse. The reason I want to do that is to be able to call the Unity3D Activity within my own "normal" Android application.

Well, I tried to follow the steps listed on this tutorial. Using all the combinations I can imagine, I did the following:

  1. I used the Unity Android project and built it (within the Unity IDE), then copied the /Temp/StagingArea/ folder to another location.

  2. I created a new Android project, using create from existing sources, setting the location of the StagingArea copy folder. This would be the Android Library Project. Check "is Library" on properties -> Android.

  3. Again, I create an Android project, import the previusly created Android Library project and classes.jar.

  4. I move the asset folder contents from the Library project to the "Activity" project. It has two subfolders, bin and libs.

  5. I modify the generated Activity to extend UnityPlayerActivity and remove the setContent line of the onCreate method. Change the package to match the Unity Player bundle id.

  6. Add the corresponding lines to manifest, basically those that are on the Library project.

So everything compiles without errors, and I can run the project, shows the splash screen, and then a black screen, playing the sounds of my Unity Scene correctly. The logcat reveals the following errors:

01-26 16:51:46.415: D/dalvikvm(2299): Trying to load lib /data/data/es.fundacionvf.unity.gps/lib/libQCARWrapper.so 0x40515a38
01-26 16:51:46.415: E/Unity(2299): Unable to find QCARWrapper
01-26 16:51:46.415: D/dalvikvm(2299): Trying to load lib /data/data/es.fundacionvf.unity.gps/lib/libQCARWrapper.so 0x40515a38
01-26 16:51:46.415: E/Unity(2299): Unable to find QCARWrapper
01-26 16:51:46.415: D/dalvikvm(2299): Trying to load lib /data/data/es.fundacionvf.unity.gps/lib/libQCARWrapper.so 0x40515a38
01-26 16:51:46.415: E/Unity(2299): Unable to find QCARWrapper
01-26 16:51:46.415: I/Unity(2299): StopQCAR
01-26 16:51:46.415: I/Unity(2299): UnityEngine.Debug:Internal_Log(Int32, String, Object)
01-26 16:51:46.415: I/Unity(2299): UnityEngine.Debug:Log(Object)
01-26 16:51:46.415: I/Unity(2299): UnityEngine.MonoBehaviour:print(Object)
01-26 16:51:46.415: I/Unity(2299): TrackerBehaviour:StopQCAR()
01-26 16:51:46.415: I/Unity(2299): TrackerBehaviour:OnApplicationPause(Boolean)
01-26 16:51:46.415: I/Unity(2299):  
01-26 16:51:46.415: I/Unity(2299): (Filename: /Applications/buildAgent/work/842f9557127e852/Runtime/Export/Generated/UnityEngineDebug.cpp Line: 34)
01-26 16:51:46.425: D/dalvikvm(2299): Trying to load lib /data/data/es.fundacionvf.unity.gps/lib/libQCARWrapper.so 0x40515a38
01-26 16:51:46.425: E/Unity(2299): Unable to find QCARWrapper
01-26 16:51:46.425: I/Unity(2299): DllNotFoundException: QCARWrapper
01-26 16:51:46.425: I/Unity(2299):   at (wrapper managed-to-native) TrackerBehaviour:stopTracker ()
01-26 16:51:46.425: I/Unity(2299):   at TrackerBehaviour.StopQCAR () [0x00000] in <filename unknown>:0 
01-26 16:51:46.425: I/Unity(2299):   at TrackerBehaviour.OnApplicationPause (Boolean pause) [0x00000] in <filename unknown>:0 

Just to mention... read these two SO questions: 1 and 2. They seem to have succeded, so it is possible to achieve following those steps (or similar).

I also found useful this topic on the Unity3D forum, which basically describes the same proccess in a clearer way.

Has anybody experienced this issue? Any suggestion or alternative?

Regards.

like image 362
mdelolmo Avatar asked Jan 26 '12 17:01

mdelolmo


1 Answers

For anyone stumbling across this, the integration of Unity3d into an android eclipse project was broken in the previous version (3.5)!

Using a newer version of Unity (successfully tested with 3.5.2) everything works fine again following these steps.

If you want to define your own activity or use Unity inside a fragment, you can use the UnityPlayer class directly. To do so you can have a look at [UNITY_INSTALLATION]\Editor\Data\PlaybackEngines\androidplayer\src\com\unity3d\player as mentioned in the Unity Forum.

Or just try this code that worked for us:

    UnityPlayer mPlayer = new UnityPlayer(getActivity()); // Put your activity object here
    int glesMode = mPlayer.getSettings().getInt("gles_mode", 1);
    boolean trueColor8888 = false;
    mPlayer.init(glesMode, trueColor8888);

    // Get the view - e.g. to return from the fragment method onCreateView:
    View view = mPlayer.getView();

Update: The first link is not available on the unity3d support page anymore, but the forum entry contains all needed steps too!

like image 157
sunadorer Avatar answered Oct 08 '22 13:10

sunadorer