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
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
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?
@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).
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 <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>return;}
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.
@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?
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 :]
I am trying to create Crashlytics plugin for android based on bowerhaus ios version. He override the C++ exit function like this :
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.
//
fclose(stdout);
NSString* stdoutString=[NSString stringWithContentsOfFile: getDocPathTo(<a href="https://forum.giderosmobile.com/profile/%2Fstdout.txt" rel="nofollow">@/stdout.txt</a>) encoding:NSUTF8StringEncoding error: NULL];
NSString* luaStack=distillLuaStackTrace(stdoutString);// 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
for (;;);
}
Is stdout.txt file also exist on Android? the point is to be able to grab the Lua error.
@bysreg basically what you should to is to monitor LogCat output for any pattern related to Lua error (this is what @bowerandy is doing in IOS). 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
@bysreg I did not mean that it is related to Gideros, more like related to Android, because monitoring logcat in all seems a bad idea, and I don't even know how it will behave in production (not debug mode).
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)
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?
Yes because it happens on the native side, and not Android Java layer and for now it is implemented, that application exits gracefully.
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.
Comments
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
cheers,
@techdojo you owe me a coffee
Likes: gorkem, techdojo, GregBUG, Scouser, ndoss, phongtt, alexzheng
Thank you
Likes: gorkem
Likes: gorkem
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
testing now...
Likes: atilim
www.tntengine.com
Thanks.
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
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?
https://sites.google.com/site/xraystudiogame
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
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.
https://sites.google.com/site/xraystudiogame
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?
https://sites.google.com/site/xraystudiogame
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)
Likes: phongtt
Likes: SatheeshJM
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
Likes: chipster123, Rickyngk, SatheeshJM
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?
About *gJavaVM_guava7androidplugin,
https://play.google.com/store/apps/developer?id=My+name+is+Originality
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:
http://stackoverflow.com/questions/4661234/how-to-constanly-monitor-logcat-file
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.