Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to integrate Unity into an Android Activity

This is my first time using Unity, and I want to integrate it into an already existing Android app.

From what I've read, you need to package your Android project into a jar file. Since you can't include the resource folder in the jar, how do I handle all of the resources for my app? The app also uses the ActionBarSherlock and ViewPagerIndicator libraries which have resources of their own as well.

I basically just need a way to click a button on Android and pop up an Activity containing the Unity stuff. I want the rest of the app to be native Android code. Thanks for the help!

like image 565
starkej2 Avatar asked Oct 04 '12 20:10

starkej2


People also ask

Can Unity export to Android?

For Unity to be able to export your game as an APK, you need to install the Android Build Support module on the Unity Editor that you are using to build your project. Under the Installs tab of Unity Hub, if you find the circled icon below your editor version, that means that Android Build Support is installed for it.

Can I open Unity project in Android Studio?

Once you have downloaded Android Studio, you need to add the Android SDK path to Unity. See Unity documentation on Android SDK/NDK setup for steps on how to do this. Once you have your Android developer environment set up, you can open your Unity Project.


2 Answers

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.

like image 186
starkej2 Avatar answered Oct 25 '22 08:10

starkej2


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.
like image 25
Parikshit Singh Shekhawat Avatar answered Oct 25 '22 07:10

Parikshit Singh Shekhawat