5 ms·
Swift-X tool to cross compile Swift and Objective-C(++) code to Android
- wben 12y agoSuper nice work. Thanks for posting.
- pavlov 12y agoFrom the project's GitHub page, some more details on what it actually does: swift-x is a python script that simplifies the compiling of Swift and Objective-C(++) code into object files. ... [It] is a two stage wrapper for clang and the swift compiler that uses the Android NDK tools to produce android compatible .o files. The first stage uses clang or swift to compile source code and emit LLVM-IR code which is passed to the Android second stage tools which compile the IR into .o files. So you get working object code, but you still need to figure out how to get Android versions of the Cocoa Touch libraries if you use any of those APIs.
- wben 12y agoI'm working building a UI library in swift that uses OpenGL for all rendering, etc. A page about this project is here: http://photovivaapp.com/SwiftUI/ http://photovivaapp.com/SwiftUI/ This runs on iOS for now, but it would be nice to get it running on android. I'm wondering how to call C code from Swift and how to call Swift from C for this project to work.
- sspiff 12y agoYou can't just take a Swift app for iOS and compile it for Android, sure. But this could be useful for people who enjoy Swift, and want to reuse blocks of logic from their iOS app to an Android port. I'm wondering though, I thought Swift compiled down to code that uses things like the Foundation framework (NSString etc), which would also be missing on Android. It would be hard to do anything without these classes, wouldn't it?
- pavlov 12y agoThere are several independent open-source implementations of Foundation like GNUStep and Cocotron. Once you have the Obj-C runtime and cross-compiler working, porting either of those to Android should be fairly simple... But I suspect that Swift may have dependencies on new or recent Foundation features which could be missing from the open-source versions (for understandable reasons, they lag behind Apple by several years).
- WoodenChair 12y agoThese guys already did port those frameworks to Android: http://www.apportable.com http://www.apportable.com
- pjmlp 12y agoIn what concerns GNUStep, has it improved the situation of a partially supported NeXTStep and Cocoa around 10.4?
- therealmarv 12y agoWhen I wanted to code a foundation of reusable code for different devices I would either do it like Dropbox and use C++ as the most common layer http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cross-platform-development/ http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cros... or use Javascript (which I can also use for web pages) for the program logic like described here http://www.skyscanner.net/blogs/developing-mobile-cross-platform-library-part-3-javascript http://www.skyscanner.net/blogs/developing-mobile-cross-plat... Also interesting http://kivy.org http://kivy.org allows you to use Python for iOS, Android, OS X and Windows. I would not bet on Swift and cross compiling it today... too bleeding edge. But interesting project... hope it matures. Good luck!
- crishoj 12y agoAnother viable — and possibly more enjoyable — approach would be to use C# for the full stack, irrespective of platform. See http://xamarin.com http://xamarin.com
- therealmarv 12y agoNo offense against C# (I like the language) but Xamarin is a commercial product https://store.xamarin.com/ https://store.xamarin.com/ which makes you dependent on Xamarin. Xamarin is definitely more advanced and I guess you can also do cross compiling UI apps. But before going the Xamarin road I would look more into QT.
- pjmlp 12y ago> But before going the Xamarin road I would look more into QT. Which is also commercial, unless you plan to release an open source app.
- lucian1900 12y agoQt has been available under the LGPL for several years now.
- empressplay 12y agoAnything that makes it easier for entrepreneurs to make their apps available on both iOS and Android is productive and welcome.
- bezalmighty 12y agoIts great to see work being put into building community tools like this for Swift, thanks for the contribution. BTW if you are in SF, we are running a Swift hackathon @ GitHub HQ in a few weeks: http://www.swifthack.splashthat.com http://www.swifthack.splashthat.com
- lukeh 12y agoFWIW I took a recent look at porting the Apple Objective-C runtime to Linux (with the vague idea that if Apple open source Swift, it might be easier to get it working with their own runtime rather than the GNUstep one). One nice thing about clang is that there's no problem outputting Objective-C code that uses the Apple runtime on other platforms: just use -fobjc-runtime=macosx. The catch is that because class, protocol, etc definitions are just data, you need a way to get notified by the runtime linker when an object is mapped into the process address space. (You could scan the current address space at startup, but that makes it difficult to support dynamic loading, although probably not impossible now that I think about it. I thought I was nearly there with ld.so audit interface, but audit modules are loaded into their own namespace, so you can't easily communicate with the global libobjc.)
- mpweiher 12y agoI got some minimal Objective-C code running on Android a while ago, see http://blog.metaobject.com/2012/12/android-ndk-now-includes-clang-with.html http://blog.metaobject.com/2012/12/android-ndk-now-includes-... This tool appears to fix the problem with the NDK make tool not recognizing .m files. I worked around this once by naming them with the .c extension and using compiler flags to set the language to Objective-C. Another time, I think I hacked the makefiles, but that was extremely painful. Of course, there's apportable (http://www.apportable.com/open_source http://www.apportable.com/open_source), their low-level stuff (runtime, Foundation) is open-source.