Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Android Plugin - Direct binding from C# to Java ?

Discussion in 'Android' started by hello1111, Nov 4, 2014.

  1. hello1111

    hello1111

    Joined:
    Apr 14, 2014
    Posts:
    13
    Hi All -
    apologies in advance if this is old territory.
    I've read Building Plugins For Android and googled around,
    and from what I can see, the stack for getting to java from C# is: C# <---> C/C++ <---> Java,
    whether you're using "Java Plugins" or not.

    Is that the case ?

    Xamarin claims to bind directly from C# to Java, but who knows what's under the hood.

    My concern is performance.
    Our Java endpoints have their own trips into C/C++,
    so we'd be crossing the JNI 2 times in one direction for stuff,
    and we'd be doing that on the order of 30 times per second from C# --> Java, and also 30 times per second from Java --> C#, so if we can skip some JNI excursions that would be great.

    cheers and TIA,
    Orion
     
  2. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,165
    This is correct.

    You can try calling native methods directly from C# code:
    Using Your Plugin from C section in http://docs.unity3d.com/Manual/PluginsForAndroid.html
    But you will need to extract these calls from Java if you want to avoid JNI.
     
  3. hello1111

    hello1111

    Joined:
    Apr 14, 2014
    Posts:
    13
    Hi Yuri - thanks for the reply, I appreciate it.

    We have a bunch of functionality in Java, and also need to access underlying OS features (notably bluetooth),
    so it sounds unavoidable to visit the JNI.