Search Unity

Help with JavaPluginSample for Android

Discussion in 'Editor & General Support' started by georgedim, Feb 4, 2012.

  1. georgedim

    georgedim

    Joined:
    Sep 14, 2011
    Posts:
    3
    Hi guys,

    I am stuck in trying to run the JavaPluginSample that Unity provides as an example for writing Android plugins. I have setup my system with the Android NDK and with Ant (although I prefer to do my Java development in Eclipse). So, although not necessary, I have compiled anew the jni.cpp into the libjni.so and the JavaClass.java into the JavaClass.class. The whole thing works if I build it as an .apk and run it on an Android device. The problem is I can't seem to run it in the editor (with the development system set to Android). Every time any command coming from the libjni.so is called I get the dreaded DllNotFoundException: jni.

    I have read pretty much everything there is out there on how to do this and I am not even sure if the Unity editor supports running Android plugins. It seems to have no problem with Windows plugins, so am I missing something?
    I have made no changes to the code provided in the example. All the files are in the places given by the example. I tried to make it work before compiling the jni.cpp and the JavaClass.java and also after. Same difference.

    I need to use this example as a base to develop my own code which brings external libraries also into the Android part of the development so it will get complicated. Thus I really need to be able to run the whole thing in the editor and not just in an actual machine for debugging purposes.

    I realize the subject is a bit esoteric and I have seen a few unanswered questions regarding the jni in the forums, but because of this, any answer to the above would be useful not only to me but to quite a few other people.

    Thanks in advance
     
  2. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Been there. Solved.

    The DLL not found stuff was so yesterday.. You have to make sure you are compiling an unmanaged C DLL, not a C++ .net DLL. You just put your interface declarations in stdfx.h and stdfx.cpp that auto generate with a new library project in Visual Studio.

    Rather than DLL with string to UT8 issues though, I recommend just use the provided samples.

    I'll save you one more day. Use Java 1.6. Where Java 1.7 doesn't work.

    I adapted the sample to build everything from the menu. Keep in mind the command files hardcode the paths to android, NDK, and Java. So you'll want to tweak that.

    Use the menu item:

    Assets->Build Android

    http://tagenigma.com/unity/AndroidJavaPluginProject003.zip