1

Target Application: Development of an Unity application for android device.The Unity application will use OpenCV for various image processing functions.

Approach Planned:

  1. Develop an OpenCV for android application in Android Studio. This will have a bridge class for sharing data with Unity.

  2. Export the android studio project into jar

  3. Use the jar and other assets in Unity as a Plugin

  4. Access the required functions for image processing using the bridge class in android using the Android Java support classes in Unity.

  5. Build the unity application for Android Platform

Experiments Done:

  1. Already did a set up for OpenCV for android in Android Studio.

  2. Tested sample applications on device by generating apk.

  3. Tested the plugin concepts in unity using DLLs for a windows based application. Dll concepts working fine for Unity.

Final Experiment--

4. Used the classes.jar generated in the build\intermediates\exploded-aar... as a plugin in Unity. It generates an apk from the unity build. The apk gets installed on a device but fails to open.(Can't see it in the apps menu)

Used this .jar approach based on an answer in the following link How to export library to Jar in Android Studio?

Problems:

  1. Most of the android plugin tutorials use Eclispe and have the export to jar function. This jar file can be used as a plugin in unity.

Queries:

  1. I found about the jar task which could be included in the gradle script. But I am not sure how to use it ? There seems to be a lot of version for the jar task creation in Android studio. How to achieve for a project using opencv in android?

  2. I am also confused whether .jar or .aar will solve my purpose?

  3. Should I try any other approach like the android library for achieving the android, Opencv and unity integration.

My take on Solutions:

  1. Generating the appropriate jar in Android Studio will solve the issues.

  2. Else go back developing the opencv for android in eclipse

Useful Links

Can Android Studio be used to create Unity-plugin compatible JARs out of Library projects?

The following project approach is almost the same which I want to acheive https://github.com/thorikawa/unity-opencv-android

Any help on this will be appreciated.

Update 24th Feb 2015

With the help of this link Can Android Studio be used to create Unity-plugin compatible JARs out of Library projects?

I am able to integrate Unity and Android.

The android studio project now contains two classes an activity class and a normal java class containing various getter functions.

I am able to call any functions of the normal java class from unity.

But unable to start the activity class from unity.

My Thoughts

  1. I guess unity generates its own manifest file while doing a build for android in unity.

  2. Changing the android studio manifest file accordingly might solve the issues.

Queries

  1. How to start an activity inside the android library from Unity?

  2. How is the android studio generated manifest file provided in unity so that unity merges it with its own generated manifest without any conflicts?

Things Tried

  1. While building in unity, if no android studio generated manifest file is provided, the app functions properly and communicates with the simple java class with getter functions.The values can be obtained in Unity.

  2. If the default manifest file is provided along with the classes.jar the app gets installed but crashes on opening. Even the app name is changed to the one provided by the android studio manifest file.

If any one could help me with this I ll be grateful. Besides I think if I solve this step integrating opencv for android won't be very tough.

Best regards, Swaroop

Community
  • 1
  • 1
swaroop
  • 93
  • 1
  • 10
  • Maybe you can use a reverse approach like ,exporting your Unity project as Eclipse project and importing it into android studio and adding your library as a module? – nexx Feb 23 '15 at 09:05
  • @nexx Got some advancement in the other approach. I have updated in my post. If I solve the issues as mentioned that might work smoothly for opencv for android too. If that doesn't work I ll take up your approach and try, Thanks for replying. – swaroop Feb 24 '15 at 12:33

1 Answers1

0

First of all you can’t use .aar files unless you have Unity5 (I don’t have but I read that aar support is added). For creating jar I use the same approach that use posted here and it worked for me.

If you have Unity5, If your project is set up as an Android library, it will output an .aar when it's built. It will show up in the build/outputs/aar/ directory in your module's directory.You need to copy those to Assets/Plugins/Android folder

If you want to open an activity from Unity since you added it inside your .jar need to declare it inside your manifest. If you are already using a custom manifest for your project just add it inside your application tag.

Otherwise you need to create a custom manifest for your project. First you need copy the Android Manifest that Unity generates when you compile your game, it’s on folder:

YourProjectname/Temp/StagingArea/AndroidManifest.xml

copy it from there to Assets/Plugins/Android folder inside Unity and add your activity of your library:

<activity android:name="yourLibraryPackagename.YourActivity"</activity> 

into that manifest inside your application tag and you should be able to open your activity.

Community
  • 1
  • 1
nexx
  • 579
  • 1
  • 7
  • 17