Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

First, let me say that this is my first experience with Unity, so the answer may be right under my nose. I've also posted this question on Unity's answers site, but plugin questions don't seem to be as frequently answered there.

I'm trying to create a plugin that allows me to access an SDK from my game. I can call SDK methods just fine using AndroidJavaObject and I can pass data to them with no issue. But there are some SDK methods that require an interface to be passed.

For example, my Java function:

public void attemptLogin(String username, String password, LoginListener listener);

Where listener; is a callback interface. I would normally run this code from Java as such:

attemptLogin("username", "password", new LoginListener() {
    public void onSuccess() {
        //Yay! do some stuff in the game

    public void onFailure(int error) {
        //Uh oh, find out what happened based on error

Is there a way to pass a C# interface through JNI/Unity to my attemptLogin function? Or is there a way to create a mimic-ing interface in C# that I can call from inside the Java code (and pass in any kind of parameter)?

Thanks in advance! :)

share|improve this question

2 Answers 2

Since Unity 4.2 there is a class called Androidjavaproxy which can do exactly what you are looking for.

This class can implements any Java interface in Unity.

share|improve this answer

Main Unity selling point is that it is cross platform. What this means for your question is that I would strongly suggest not calling SDK functions directly, but doing as much as possible through Unity provided API's. In short do the authentication using Unity API. This way, you will write connectivity code once, and it will work on all platforms. Unity will take care of the platform differences. In particular look at:

If you really need to interoperate C# and Java, I am sorry but my answer is lacking on this.

share|improve this answer
This is true, but in this case I am writing the plugin, not the game ;) –  nbadal Oct 3 '12 at 0:37
Ah, sorry. Did not get that from the question. Good luck. –  MikiJ Oct 3 '12 at 0:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.