Quick Links: Gideros Home | Download Gideros | Developer Guide
Creating a simple Android plugin - Gideros Forum
Creating a simple Android plugin
  • This discussion was created from comments split from: Android plugin example.
  • atilimatilim +1 -1 (+7 / -0 )
    Hi all,

    First of all, sorry for the late reply. And here are the steps about creating a simple Android plugin:

    Part 1 (build your plugin)
    --------------------
    1. Download the attached zip file and extract to a directory. It contains the sources of BitOp plugin, header files and libgideros.so (for armv6 and armv7) (these files also come with the original Gideros installation).
    2. Also this zip file contains BitOp/jni/Android.mk. This is the makefile of the plugin.
    3. Go to the BitOp directory and execute ndk-build
    4. Now your libbitop.so (for armv6 and armv7) should be ready at BitOp/libs


    Part 2 (create your own Gideros Android Player)
    ---------------------------------------
    1. Create a project with name MyGiderosAndroidPlayer
    2. Without adding any files, export it as an Eclipse project
    3. Delete the directory assets/assets
    4. Deploy it to your device. Now you have a Gideros Andoid Player.

    Part 3 (adding your plugin)
    ----------------------
    1. Copy libbitop.so files to libs directory of MyGiderosAndroidPlayer project
    2. Open your ...Activity.java file and add the line
    System.loadLibrary("bitop");

    under the line System.loadLibrary("gideros");
    3. Deploy it.

    Part 4 (testing your plugin)
    ----------------------
    Test your plugin with this Lua file
    require("bit")
    print(bit.tohex(3133078222))


    please ask if you stuck in any step.

    cheers,

    @techdojo you owe me a coffee :)
    BitOp-plugin.zip
    2M
  • Also I'm attaching the resulting Gideros Android Player with BitOp plugin.
    MyGiderosAndroidPlayer.zip
    2M
  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    @atilim oh, I think whole Gideros community owes you much more ;)
    Thank you

    Loves: gorkem

  • techdojotechdojo +1 -1 (+1 / -0 )
    @atilim - the coffee was for Scouser to stop him crying, but this is just for you.
    Coffee.jpg
    225 x 225 - 12K

    Loves: gorkem

    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • GregBUGGregBUG +1 -1 (+1 / -0 )
    thanks atilim!!!

    testing now... :)

    Loves: atilim

    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • @techdojo uhh.. got it now :) anyway, thanks for the coffee. I can share it with @Scouser :P
  • @atilim, You're a baby face! :))

    Thanks.
  • Thanks for the coffee :) and also the plugin howto. I can see where I was going wrong now and hopefully I will get to test it at the weekend.
  • Part 4 (testing your plugin)
    do you mean add a lua file to MyGiderosAndroidPlayer and export it again, then run the exported project on device in eclipse?

    Or maybe just create a new gideros project and run it in MyGiderosAndroidPlayer in gideros studio?


  • @alexzheng: As I understand it, you run the new MyGiderosAndroidPlayer.apk as a replacement player on your phone. This player would have your new plugin incorporated.
  • @Scouser
    Maybe any of the above method works,
    the first is necessary for final release and the second is handly for development.
    I will try both when I get home.
  • yes,I have tried both.
    As I undertand, the orignal giderplayer come with gideros studio is just an empty project without asset just like Part 2, when added some asset to it,it will act as a normal app(will not listen for connection),is that right?

    And any tutorial using java code as plugin?
  • @atilim, (and everyone else :) ) what can I read to learn how to get the native android keyboard to pop up and feed me the string when closed? :-B
  • RickyngkRickyngk +1 -1 (+1 / -0 )
    @atilim
    I see that, we are lacking of some features in bitop example.

    Last few days, I try to write an android plugin which support three functions
    (done)
    + LogI: write down a log message in android console by using __android_log_print
    + GetDeviceModel: get Android device model information (by using android.os.Build.MODEL of Android SDK)
    + Popup an alert if press back key.

    Bitop is good reference for the first one, but not for last twos. I modified some in source to support. And here is my suggests:

    + we could replace/modify default macros REGISTER_PLUGIN. We need to store JavaVM inside plugin to connect to Java side.
    + Support macros for quick connect from JNI to JAVA side.
    + Support Handler in Java-side to handler UI request from JNI (avoid crash by thread)
    + Add an RelativeLayout, instead of add directly mGLView to content-view. By this way, we could add more view into screen (such as admob view).

    My JNI-Java connection template (I used http://stackoverflow.com/questions/9304185/how-to-call-java-function-from-c with some changes)

    void Jni_Todo(....)
    {
    // step 1: Get environment pointer

    JNIEnv *env = 0;
    int status;
    int isAttached = 0;

    if ((status = (*gJavaVM_guava7androidplugin).GetEnv( (void**)&env, JNI_VERSION_1_6)) < 0)
    {
    if ((status = (*gJavaVM_guava7androidplugin).AttachCurrentThread(&env, NULL)) < 0)
    {
    isAttached = 1;
    }
    }

    // step 2: Get JAVA class pointer. For example with Java class com.gideros.android.MyActivity

    jclass cls = (*env).FindClass( "com/giderosmobile/android/MyActivity" );
    if (!cls)
    {
    if (isAttached) (*gJavaVM_guava7androidplugin).DetachCurrentThread();
    return;
    }

    // step 3: Get JAVA function pointer. For example with Java func: static void todo()

    jmethodID method = (*env).GetStaticMethodID(cls, "todo", "()V");
    if (!method)
    {
    if (isAttached) (*gJavaVM_guava7androidplugin).DetachCurrentThread();
    return;
    }

    //step 4: call java function
    (*env).CallStaticVoidMethod(cls, method); //or others function from http://java.sun.com/docs/books/jni/html/fldmeth.html
    return;
    }


    Loves: phongtt

  • chipster123chipster123 +1 -1 (+1 / -0 )
    I almost understand this 3:-O

    Loves: SatheeshJM

  • atilimatilim +1 -1 (+3 / -0 )
    Hi @Rickyngk,

    About your suggestions,

    1. Totally agree. I'll provide a function so that you can get JavaVM.
    2. Yes, JNI is big and complicated. I'll try to provide macros.
    3. Yes, rendering and executing Lua codes are done on a separate thread. Therefore, any UI action should be run by using the function Activity.runOnUiThread to avoid crashing (And I should emphasize this in the documentation).
    4. Totally agree.

    thanks
  • @Rickyngk
    Hi,
    Thanks for your JNI template. Can you explain a bit on how to use the template?
    And what exactly is the *gJavaVM_guava7androidplugin pointer?
  • @SatheeshJM: that's just for testing and my code so messy, waiting for official code from @atilim

    About *gJavaVM_guava7androidplugin,


    JavaVM *gJavaVM_guava7androidplugin = 0;
    JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void *res)
    {
    gJavaVM_guava7androidplugin = vm;
    g_registerPlugin(g_pluginMain_guava7androidplugin);
    return JNI_VERSION_1_6;
    }


    it's a VM pointer, that help me to invoke a java function from C
  • atilim said:


    Part 2 (create your own Gideros Android Player)
    ---------------------------------------
    1. Create a project with name MyGiderosAndroidPlayer
    2. Without adding any files, export it as an Eclipse project
    3. Delete the directory assets/assets
    4. Deploy it to your device. Now you have a Gideros Andoid Player.


    @ar2rsawseen it should be in FAQ section definitely :) it saved my hair :]

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters