title: Develop an Android Plugin (Involving OpenCV for android) for Unity in Android Studio
body: <p><strong>Target Application:</strong> Development of an Unity application for android device.The Unity application will use OpenCV for various image processing functions.</p>
  
  <p><strong>Approach Planned:</strong> </p>
  
  <ol>
  <li><p>Develop an OpenCV for android application in Android Studio. This will have a bridge class for sharing data with Unity.</p></li>
  <li><p>Export the android studio project into jar </p></li>
  <li><p>Use the jar and other assets in Unity as a Plugin</p></li>
  <li><p>Access the required functions for image processing using the bridge class in android using the Android Java support classes in Unity.</p></li>
  <li><p>Build the unity application for Android Platform</p></li>
  </ol>
  
  <p><strong>Experiments Done:</strong></p>
  
  <ol>
  <li><p>Already did a set up for OpenCV for android in Android Studio.</p></li>
  <li><p>Tested sample applications on device by generating apk.</p></li>
  <li><p>Tested the plugin concepts in unity using DLLs for a windows based application. Dll concepts working fine for Unity.</p></li>
  </ol>
  
  <p>Final Experiment--</p>
  
  <p><strong>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)</strong> </p>
  
  <p>Used this .jar approach based on an answer in the following link
   <a href="https://stackoverflow.com/questions/16763090/how-to-export-library-to-jar-in-android-studio">How to export library to Jar in Android Studio?</a></p>
  
  <p><strong>Problems:</strong></p>
  
  <ol>
  <li>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.</li>
  </ol>
  
  <p><strong>Queries:</strong></p>
  
  <ol>
  <li><p>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?</p></li>
  <li><p>I am also confused whether .jar or .aar will solve my purpose? </p></li>
  <li><p>Should I try any other approach like the android library for achieving the android, Opencv and unity integration.</p></li>
  </ol>
  
  <p><strong>My take on Solutions:</strong></p>
  
  <ol>
  <li><p>Generating the appropriate jar in Android Studio will solve the issues.</p></li>
  <li><p>Else go back developing the opencv for android in eclipse</p></li>
  </ol>
  
  <p><strong>Useful Links</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/23483143/can-android-studio-be-used-to-create-unity-plugin-compatible-jars-out-of-library">Can Android Studio be used to create Unity-plugin compatible JARs out of Library projects?</a></p>
  
  <p>The following project approach is almost the same which I want to acheive
  <a href="https://github.com/thorikawa/unity-opencv-android" rel="nofollow noreferrer">https://github.com/thorikawa/unity-opencv-android</a></p>
  
  <p>Any help on this will be appreciated.</p>
  
  <p><strong>Update</strong>  <strong>24th Feb 2015</strong></p>
  
  <p>With the help of this link
  <a href="https://stackoverflow.com/questions/23483143/can-android-studio-be-used-to-create-unity-plugin-compatible-jars-out-of-library">Can Android Studio be used to create Unity-plugin compatible JARs out of Library projects?</a></p>
  
  <p>I am able to integrate Unity and Android.</p>
  
  <p>The android studio project now contains two classes an activity class and a normal java class containing various getter functions.</p>
  
  <p>I am able to call any functions of the normal java class from unity.</p>
  
  <p>But unable to start the activity class from unity.</p>
  
  <p><strong>My Thoughts</strong> </p>
  
  <ol>
  <li><p>I guess unity generates its own manifest file while doing a build for android in unity.</p></li>
  <li><p>Changing the android studio manifest file accordingly might solve the issues.</p></li>
  </ol>
  
  <p><strong>Queries</strong></p>
  
  <ol>
  <li><p>How to start an activity inside the android library from Unity?</p></li>
  <li><p>How is the android studio generated manifest file provided in unity so that unity merges it with its own generated manifest without any conflicts?</p></li>
  </ol>
  
  <p><strong>Things Tried</strong></p>
  
  <ol>
  <li><p>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.</p></li>
  <li><p>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.</p></li>
  </ol>
  
  <p>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.</p>
  
  <p>Best regards,
  Swaroop</p>