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!
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
- Now replace Activity with UnityPlayerActivity as below
public class MainActivity extends UnityPlayerActivity
- comment the line setContentview(R.layout.main).
- Now run your app.
In some scenario developers using native platform technologies (like Android/Java & iOS/Objective C) want to include in their apps/games features powered by Unity (usually for 3D/2D Real Time Rendering), like AR experience, interaction with 3D models, 2D mini games.
You can now insert features powered by Unity (Starting with Unity 2019.3.a2) directly into your native
mobile applications. These features include, but aren’t limited to, 3D
or 2D real-time rendering functions such as augmented reality, 2D
mini-games or 3D models.
You can integrate the Unity runtime components and your content in a
native platform project. The Unity Runtime Library exposes controls to
manage when and how to load/activate/unload within the native
- Android Studio 3.4.2+
- Unity version 2019.3.0b4+
While we tested many scenarios for Unity as a library hosted by a native app, Unity does not control anymore the lifecycle of the runtime, so we cannot guarantee it’ll work in all possible use cases.
- Unity as a Library supports rendering only full screen, rendering on a part of the screen isn’t supported.
- Loading more than one instance of the Unity runtime isn’t supported.
- You may need to adapt 3rd party Plug-ins (native or managed) to work properly.
How it works
The build process overall is still the same, Unity creates the iOS Xcode and Android Gradle projects, but to enable this feature we changed the generated iOS Xcode and Android Gradle projects, they now have the following structure:
- A library part (iOS framework and Android Archive (AAR) file) that includes all source & plugins
- A thin launcher part that includes app representation data and runs library
Integration Unity as a library in native Android app
Step by step explanations on how to include the Android library part into your native application when needed.
Integration Unity as a library in native iOS app
Step by step explanations on how to include the iOS library part into your native application when needed.