COMMUNITY

Create native libs for iOS and Android in Haxe

ios
android

(Uldis Baurovskis) #1

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


(david mouton) #2

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


#3

my current list of extensions I use and maintain -> https://github.com/PXshadow/App/tree/master/src/ext also the haxeextension project may be what you’re looking for here -> https://github.com/HaxeExtension


(Jérémy Faivre) #4

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: )


(Thomas Fétiveau) #5

I’ve crossed this project some time ago which seemed quite promising but lacks sadly someone to work on it: https://github.com/Aurel300/plumob

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


(Uldis Baurovskis) #6

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


(Ian Harrigan) #7

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 (https://www.youtube.com/watch?v=cijUTbMKMHI), 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


(Dmitry Hryppa) #8

There is also Haxe bindings for React-native:


(Uldis Baurovskis) #9

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.