JNI Lime CallHaxe - init not called

I’m building a project that calls Haxe from Java and I’m testing it on two android devices. The first running Android 5.0 is working fine but when I build to the other device running Android 4.2.2 then Haxe is not being called from Java. I looked into logcat and whenever I try to call Haxe I get this error: "Lime CallHaxe - init not called."
This is the code that I’m using to call Haxe:

Extension.callbackHandler.post(new Runnable() 
	@Override public void run () 
		_callback.call("onSetupSuccess", new Object[] {});

I’m using the latest libs. Tried cleaning the project, building with -Dnext and -Dlegacy but no clue why it does work on one device and not on the other.
Any ideas?

Have you tested the other way around? Haxe calling Java? It might be a timing issue

Yes, there is no problem calling Java from Haxe. First thing I do is call Java and send HaxeObject to it. Then it is supposed to call Haxe on some various third-party API events.

Could you try calling Java from Haxe first, then doing a call back to Haxe later, in response? I’m wondering if it might be a race condition – like Java calling Haxe before its initialized?

I’m calling Java from Haxe first and I’m sending it a HaxeObject. Then Java is calling Haxe using the provided HaxeObject. I checked and I don’t see any way Java could call Haxe before it’s initialized.
Logcat also shows this before any calls to Java are made:
D Trying to load lib /data/app-lib/com.mypackage.name-1/libmyextension.so 0x41599d60
D Added shared lib /data/app-lib/com.mypackage.name-1/libmyextension.so 0x41599d60
D No JNI_OnLoad found in /data/app-lib/com.mypackage.name-1/libmyextension.so 0x41599d60, skipping init

Is that related to the problem?

Would you mind trying to add some trace messages to lime.system.JNI, to see if it is calling the “init” function? That seems to be where the JNI callback is set

I have added the traces to lime.system.JNI but none appeared. I’m using HaxeFlixel which requires legacy so I added traces to openfl._legacy.utils.JNI and the traces were visible in logcat. It kinda seems like I’m calling Java from Legacy but Java is trying to call Next and that is why init was not called? I’m confused.

Oh, legacy. Do you have a way of testing a small project without using legacy, so we can tell if this affects both versions, or just the legacy code? The newer code is easier for us to make changes to, so if it affects both versions, that would give us a better ability to test out potential changes

The more I get into this problem the more interesting things happen.

I’ve made a small project just to test this and both Legacy and Next work fine. There is going to be some text so I decided to separate each action. Here are some actions and their outcomes:

action: made a copy of my big project, stripped it out so only Main.hx is left and added a extension just to test Java-Haxe and Haxe-Java communication.
outcome: it works fine

action: added haxeflixel to libs
outcome: both lime and lime-legacy are used, app crashes when calling Haxe and logcat shows this error “CFFILoader.h E Could not API gc_set_top_of_stack

action: changed the package name
outcome: the CFFILoader error no longer appears o_O WTF?

action: changed the package name of the small project to the big project’s
outcome: guess what? CFFILoader error

Why the device reacts differently to this particular package name?
I’m going to be adding functionality of the big project piece by piece to see where the CFFILoader error disappears and the problem with Init appears.

Ah hah, perhaps something occurs when both Lime and Lime legacy end up calling JNI code, or something like this?

We need to find why Flixel includes both Lime and Lime legacy (OpenFL should be excluding Lime classes when you are using -Dlegacy)


I have a similar problem like this.

The error is:

E/CFFILoader.h(19607): Could not API gc_set_top_of_stack
E/CFFILoader(19607): Could not find function:gc_set_top_of_stack
F/libc    (19607): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 19607 (yer.jardinelena)

I’m not using HaxeFlixel. I’m using HaxeUI, and it uses legacy code too. For now, the problem is reproduced in a Huawei P7 with Android 4.4.2. I have tested in a Xperia Z1 with Android 5.1 and it works.

It occurs with 2 projects that i’m working. One of them uses the extension-webview . The other uses a custom extension to manage the Wifi State, and it crashes when the callback is called.

Any ideas?

Thanks in advance.

I finally got my project running on both devices. I was getting the CFFILoader error because as it seems, both Lime and Lime-legacy was used. HaxeFlixel requires legacy but Lime was also included in the build because something in the code was using it and I found what. I tried forcing legacy build with -Dlegacy and got some ‘lime_application_create_prime’ error which I was able to pinpoint.
It turns out that there was this little evil import which caused all the problem:

import lime.app.Application;

It was added by mistake and I didn’t even know about it.
@aWaKeNiNG Maybe you have the same problem.

Thanks! Tomorrow i will test it. My partner has the Huawei P7. I will post the results.

Where was that import? :slight_smile:

Thanks @niceneasy,@singmajesty. It works. I hadn’t any compile error with -Dlegacy, but it generates a smaller apk (-2MB, without liblime.so file) and it works now. :smiley:

It was somewhere in my code. Autocompletion in FD sometimes adds weird imports.