It looks like you're new here. If you want to get involved, click one of these buttons!
gorkem, techdojo, GregBUG, Scouser, ndoss, phongtt, alexzheng
// step 1: Get environment pointer
JNIEnv *env = 0;
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 (isAttached) (*gJavaVM_guava7androidplugin).DetachCurrentThread();
// step 3: Get JAVA function pointer. For example with Java func: static void todo()
jmethodID method = (*env).GetStaticMethodID(cls, "todo", "()V");
if (isAttached) (*gJavaVM_guava7androidplugin).DetachCurrentThread();
//step 4: call java function
(*env).CallStaticVoidMethod(cls, method); //or others function from <a href="http://java.sun.com/docs/books/jni/html/fldmeth.html" rel="nofollow">http://java.sun.com/docs/books/jni/html/fldmeth.html</a>
chipster123, Rickyngk, SatheeshJM
JavaVM *gJavaVM_guava7androidplugin = 0;
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void *res)
gJavaVM_guava7androidplugin = vm;
Part 2 (create your own Gideros Android Player)---------------------------------------1. Create a project with name MyGiderosAndroidPlayer2. Without adding any files, export it as an Eclipse project3. Delete the directory assets/assets4. Deploy it to your device. Now you have a Gideros Andoid Player.
void exit(int status)
// We replace the standard C exit that Gideros calls when it finds a Lua stack error.]
// First close the stdout file to flush it and the all important stack trace.
NSString* stdoutString=[NSString stringWithContentsOfFile: getDocPathTo(<a href="https://forum.giderosmobile.com/profile/%2Fstdout.txt" rel="nofollow">@/stdout.txt</a>) encoding:NSUTF8StringEncoding error: NULL];
// Assign this as a custom key for Crashlytics
[Crashlytics setObjectValue: luaStack forKey: <a href="https://forum.giderosmobile.com/profile/LUASTACK" rel="nofollow">@LUASTACK</a>];
// Now force a crash
[[Crashlytics sharedInstance] crash];
// We'll never reach here - this is just to avoid a compiler warning
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
3. Deploy it.
Part 4 (testing your plugin)
Test your plugin with this Lua file
@techdojo you owe me a coffee
Likes: gorkem, techdojo, GregBUG, Scouser, ndoss, phongtt, alexzheng
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
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?
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.
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?
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
+ 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)
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.
Likes: chipster123, Rickyngk, SatheeshJM
Thanks for your JNI template. Can you explain a bit on how to use the template?
And what exactly is the *gJavaVM_guava7androidplugin pointer?
I got err on : ENV = g_getJNIEnv(); => function g_getJNIEnv() could not be resolved
He override the C++ exit function like this :
But I actually have not found a way to monitor log output on Android, so it would be possible to save it in separate file.
Now I don't say there is no way, but currently I did not find any way. Just wanted to note, so you would not spend so much time on it. Sorry
Without crash report, it's impossible for me to determine what error the user experienced
And that crash was not reported to console, does not mean it was the Lua error (what you are doing with reading the logs is only related to getting Lua errors)
But if you insist, this seems to be what you are looking for:
I have tried the code in the link and have successfully managed to capture android log. But it seems the root of this problem is that the crash from lua doesnt cause an exception in Android. I tried listening for uncaught exceptions using code from here : http://stackoverflow.com/questions/7370981/how-to-catch-my-applications-crash-report but nothing was caught when there was a lua error
Is there any specific reason why lua error does not make exception?
So what you could do, is something like this
In application onDestroy event (when app exits), check the logcat for lua keyword, and if there is something, then save the logs to a file. And then probably on next initialization of app, check if there is anything in the file and create Crashlytics custom exceptions. (or maybe custom exception can work already inside onDestroy method, don't know need to experiment)
I could do that. I dont know about the internal of gideros, but i think making an app crash when lua did an error might solve many problems(android would then automatically report that to the developer console).
but yeah, for the mean time, i will have to make do with that.