Create native libs for iOS and Android in Haxe

Hi,
was curious if someone has written native libs for iOS and Android in Haxe, (so it can be used from the native side on both platforms). Like used with Swift on Xcode and Java in Android project.

Have investigated topic a bit and found a few tries and similar questions.
How to create iOS libs
Haxe to Obj-C lib
Haxe Java lib

Saw some libs as well:
https://github.com/jeremyfa/hx2objc

Before trying out these solutions wanted to ask if someone has succeeded to build shared lib for these platforms, or there were showstoppers on the way :slight_smile:

Thank you

1 Like

Hi,
I don’t remember how but I used NME to do that.

I talked about it few years ago here
https://groups.google.com/forum/m/#!searchin/haxelang/Nme/haxelang/cgNoFTw9M1Y

my current list of extensions I use and maintain → App/src/ext at master · PXshadow/App · GitHub also the haxeextension project may be what you’re looking for here → Haxe Extensions · GitHub

1 Like

Most haxe “native extensions” are usually about providing iOS or Android API to Haxe and you want to do the other way around so you are mostly on your own building a solution. That said:

You found my experiment (hx2objc). It is probably very incomplete, but the proof of concept worked. I think it is possible to create a macro that generates bindings to plug Haxe/C++ to iOS through Objective-C++ files (and Objective C header which is Swift compatible as well).

On Android, the same technique can be used to generate JNI bindings (but you also have the option to simply create a java library from Haxe depending on what you are doing).

So, to answer your question “are there any showstoppers on the way”, I would say no, it’s definitely doable and can work very well, but it’s not easy to setup because the most viable option in my opinion is to plug Haxe/C++ generated code to iOS/Android so you need to have good knowledge of C/C++, how Objective-C, Objective-C++ and Swift can interact together (as well as Java and C++ on Android) and you will also need to take a closer look at how to play well with HXCPP’s generated C++ to make Haxe <-> Objc conversion or Haxe <-> JNI types conversion. That’s basically what I started to do on iOS with my experiment “hx2objc”.

I believe haxe is a very good option (and a good alternative to “raw C++”) if you need to create a big (non UI) library that will be shared between iOS and Android. I used to work on a big codebase that would have benefited a lot from this solution, but at that time I didn’t know Haxe and HXCPP well enough to do so. If today I were in the same situation I would probably consider very seriously this option and build something up. (Un)fortunately I don’t need any of this anymore on my current projects, so I stopped exploring generating bindings from Haxe. I however did the opposite: parsing objc and java files to generate haxe-compatible interfaces, which requires similar knowledge, and may be helpful to look at if you want to see how types can be converted between Objc/Swift and Haxe/C++ (especially hairy cases like converting Objective-C blocks to/from Haxe callbacks :grimacing:). There are also example projects that demonstrate how to run HXCPP code in Xcode project and Android Studio project, which is basically what you would do when plugging a Haxe library to iOS or Android.

I would also add that building such solution should not depend on anything like lime, openfl, nme… That’s mostly a “binding generated C++ code to iOS or Android” problem (which doesn’t stop you from using these after, but that’s another story with its whole load of problems to solve :wink: )

I’ve crossed this project some time ago which seemed quite promising but lacks sadly someone to work on it: GitHub - Aurel300/plumob: Simple toolchain for mobile development with Haxe

If there was some quite polished tool to write native apps for Android and iOS with Haxe, I’d certainly use it…

2 Likes

Thank you all for input, looks like it will be quite tough journey :slight_smile:

Bit of a plug here, but haxeui can handle android native, its only just been released however, and there is alot of that isnt linked up (Little bit of rambling about #HaxeUI for desktop, web and mobile - YouTube), but its certainly something that will eventually function similar to the other backends. Note, that at the moment you have to use the new-component-method branch of haxeui-core (it will become master “shortly”) :smiley:

As for iOS im not sure, if im honest even resetting my apple id has been a pain (need security questions to reset security questions - nice). I think Hugh has some bindings for C++ that will work with objective-c, but ive yet to test them out (i do have an, old, iphone now though to test things on).

I also remember a while ago i found that there was “something” that could use Lua to create iOS applications. It wasnt haxe related, but since haxe has a Lua target i figured it might be worth checking out.

… … Just need to remember how i spelt my mothers maiden name, what street i grew up on, and what my favourite book is. :confused:

Cheers,
Ian

2 Likes

There is also Haxe bindings for React-native:

2 Likes

Hi @ianharrigan yes i saw native android target for haxe-ui, for android I was considering to try it out, sadly for iOS I have requirement to link it with existing swift code and xcode project, so need to create static library with bindings.

Hi, did you have any solution about this?

This is something I’m actively working on at the moment, I use a macro to generate a framework + bindings that you can drag and drop into Xcode and interface with via C or Swift (will have something similar for Android soon)

It’s not open source yet but I expect it to be within a couple months :slight_smile:

What’s the use-case? Is it for games or for general purpose code? (I can release a version that provides a graphics context and input events sooner)

Update: It’s open source now :slight_smile:

Is it necesary to go via C since hxcpp can generate ObjC++? Or Is the ObjC++ not really useful from Swift since it’s more just C++ renamed to *.mm files and so going via C like this is better?