building an android library

118 views
Skip to first unread message

Romain Texier

unread,
May 28, 2013, 12:23:49 PM5/28/13
to haxe...@googlegroups.com
Hi, 

I'm having an issue creating a graphical library for Android.
haXe/NME creates Android app and not a library.
Is there a compilation option to build an android library ?

I think that a Jar can be a solution. I include all the .class and the assets in a Jar file. 
I include this Jar in my main program, but conflicts happen (R.class and some other)
Is making a Jar a good idea ?

Regards,
Romain

Cauê Waneck

unread,
May 28, 2013, 1:57:55 PM5/28/13
to haxe...@googlegroups.com
Hi!

Are you planning to use this graphical library with NME?


2013/5/28 Romain Texier <romain...@sharplab.fr>

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Hugh

unread,
May 29, 2013, 12:16:50 AM5/29/13
to haxe...@googlegroups.com
Hi,
The haxe compiler creates a ".so" on android from just the haxe code.  NME then adds another .so and builds it into an app.
So if you do:

haxe -main Main -cpp cpp -D android

You will get just your classes built into a .so, which you can then put in an app/apk using something like:

Hugh

Hugh

Romain Texier

unread,
May 29, 2013, 7:51:41 AM5/29/13
to haxe...@googlegroups.com
> Are you planning to use this graphical library with NME?
NME will provide the low level functions.
My library will provide higher level function.

Thank Hugh.
The first part work fine.

I create the .so (  haxe -main Mylib -cpp cpp -D android  -lib nme --remap flash:nme )
Then I put the library in the libs/ directory. My java/android project loaded the library "System.loadLibrary("Mylib")".
But I can't access to the function. "private native static void myfct();" doesn't work.
I read my binary library (with nm -D libMylib.so ) and I don't see my functions symbol.
How can I export my class or function in the .so ?
Maybe I must do something similar of "DEFINE_PRIM" in neko.h


Regards,
Romain

Hugh

unread,
May 30, 2013, 1:28:21 AM5/30/13
to haxe...@googlegroups.com
Hi,
You can probably get a better view of the symbols with "objdump -T" (from memory) rather than "nm".
The hxcpp compiler by default turns off the visibility of symbols from android-toolchain.xml
 <flag value="-fvisibility=hidden"/>

If you are trying to call your code from java, you need to do the jni decorations (and force the visibility) with package names etc, like the functions in NME Jni.cpp, eg:

extern "C"
{

#ifdef __GNUC__
#define JAVA_EXPORT __attribute__ ((visibility("default"))) JNIEXPORT
#else
#define JAVA_EXPORT JNIEXPORT
#endif


JAVA_EXPORT void JNICALL Java_org_haxe_nme_NME_onCallback(JNIEnv * env, jobject obj, jlong handle)
{
  ...
}

}


Hugh

Romain Texier

unread,
May 31, 2013, 9:58:03 AM5/31/13
to haxe...@googlegroups.com
Hi,

Thanks Hugh.

My haxe library can be call from Java. But it's an ugly hack.

@:functionTailCode('} extern "C" {
#include "jni.h"

#ifdef __GNUC__
#define JAVA_EXPORT __attribute__ ((visibility("default"))) JNIEXPORT
#else
#define JAVA_EXPORT JNIEXPORT
#endif
JAVA_EXPORT void JNICALL Java_com_myapp_ClassExport_fctjava(JNIEnv * env, jobject obj/*, jlong handle*/)
{
    MyLib_obj::myfct();
} ')
static public function fct() : Int   { return 0; }
Reply all
Reply to author
Forward
0 new messages