Android JNI or native code

Hi

I wanted to get some clarification on this since it looks like things have recently changed with OpenFL. I just finished reading this post: JNI in latest Lime

I just found haxe/ openfl and I really like what I see. I had a question about some plugins/libs such as google play services, or other third party libs?

Also if I have some C, C++ code that works in a cross platform way that I would like to call, how can I do that?

You should check out the repo collection at https://github.com/openfl
There are a bunch of 3rd party libs there to get you started.

You should be able to use native code in any native target, but the Android JNI helper code is available only in -Dlegacy right now (openfl test android -Dlegacy) but will be available in the newer Android target in the future :slight_smile:

Approximately, do you know the timeline for that? (mobile support without legacy) :kissing_smiling_eyes:

Within the next couple months? Android support is working pretty well, but I’m not yet sure how we want to support the JNI helper stuff (but I know it’s important for extensions) :slight_smile:

Oki, thank you :yum:

Hi guys

It’s been a while and I’ve avoided really getting into openfl because of the lack of JNI support since I mainly write android apps. What’s the status of the JNI support as of now?

It’s been a few months now.

Looks like it’s available for both legacy and next!

I tried to build legacy app (3 JNI extensions) without -Dlegacy flag and it’s compiled fine, but after run i got the errors:

E/ExtendedExtractor: Failed to open MM_PARSER_LIB, dlerror = Cannot load library: load_library[1096]: Library 'libmmparser.so' not found 
E/ExtendedExtractor: Failed to open MM_PARSER_LITE_LIB, dlerror = Cannot load library: load_library[1096]: Library 'libmmparser_lite.so' not found 
A/libc: Fatal signal 11 (SIGSEGV) at 0x00000004 (code=1)

Full logs:


Is that related to your application, or a native extension? I’ve never heard of that library before – not related to OpenFL.

Perhaps you could try an OpenFL sample, first, and see if those are running for you without legacy?

Do you now… I tried to compile openfl-samples 3,3,1.
“openfl test flash” - works fine
“openfl test android” - compilation error at the end for all projects (with -Dlegacy flag same):

C:\android\sdk\tools\ant\build.xml:888: The following error occurred while executing this line:
C:\android\sdk\tools\ant\build.xml:890: The following error occurred while executing this line:
C:\android\sdk\tools\ant\build.xml:902: The following error occurred while executing this line:
C:\android\sdk\tools\ant\build.xml:283: null returned: 1

PS: Win 7 x64, all haxe libs are fresh, android sdk, ndk, java sdk and ant from “openfl setup android” command

Weird. Are your Android build tools up-to-date?

PS: Win 7 x64, all haxe libs are fresh, android sdk, ndk, java sdk and ant from “openfl setup android” command

+Yes, android sdk updated too.

and “platform build tools”, etc through the SDK manager? I can’t say I’ve seen this before

Yes, ofc through sdk manager)
I will try to compile openfl-samples on office PC tomorrow. And on wife’s notebook =)

Google returned me back to forum)
Problem was with “,” symbols in path openfl-samples\3,3,1… Android Build tools doesn’t like this chars =
Samples work fine now on android.

Joshua recommends copying the sample project into another folder using “openfl create [sample project name].” I assume that’s so you can make changes without messing up the original, but this could be another reason.

1 Like

Yes, i read samples readme, but i’m so lazy :grin:

But sample with text fields throws the error:

I/trace   (18578): Assets.hx:240: [Assets] There is no Font asset with an ID of "assets/LIBERATIONSERIF-REGULAR.TTF"

And my app without legacy flag gets runtime crash when i try to create textfield.

var mainFont:String = Assets.getFont("fonts/obelix.ttf").fontName;
var smallTipsFont:String = Assets.getFont("fonts/europanuova.ttf").fontName;	
Lib.trace("mainFont = " + mainFont);
Lib.trace("smallTipsFont = " + smallTipsFont);

Android -Dlegacy output:

mainFont = fonts/obelix.ttf
smallTipsFont = fonts/europanuova.ttf

Without flag, same device:

mainFont = ����������������ˆ󛸰󚈈
smallTipsFont = ����󦅰��������Ԁ������������𰐐����񰜀

What is the font name of these fonts when you open them on your computer? (Windows font info, Mac font book, etc)

(BTW, here’s the fix in the sample https://github.com/openfl/openfl-samples/commit/db0f70f2300982a4aab2c2cd8adbccb963b1bb61)