Skip to main content

Swift on Android

Running Swift code on Android

The biggest issue here is going to be a missing SwiftCore library. Right now Apple is shipping one for iOS, OS X and Watch OS. But that's it - and obviously they don't ship an Android version.

However, not all Swift code requires the SwiftCore library, just like not all C++ code requires the STL. So as long as we use the subset of Swift that doesn't hit SwiftCore, we should be ok.

Romain Goyet

How to Use Apple Swift to Make an Android App
Our best course of action to get something working quickly was to take Swift code and compile it into Java source code — and then take it into the Android development environment to finish building it into an installable app. So we started in Xcode, where we wrote the Swift code. Then we tested it, including running it on an iPhone or in the iPhone Simulator, and ran a custom compiler that parsed the Swift code and output Java source code (adjusting any necessary syntax, and substituting appropriate Android calls for any iOS native ones). Then we moved it into Android Studio to finish the build process and produced the Android APK.

ArcTouch

Is it possible to make Android apps with Swift?
The big questions are:

1) Should Swift compiles to Dalvik? This probably require making a LLVM backend to Dalvik. This will be the opposite of a RoboVM approach, and there are been some tentatives to do LLVM to Bytecode, so, it might work.

2) Should Swift compiles to NDK output (Android native). This would probably be a more conventional approach for the LLVM architecture. The trick is that the NDK get a very raw API for building UI, so the developers will have to reimplement the UI component set. 

3) Should Swift be just wrapper to the "Dalvik" UI Component set, and Swift developers will have to learn the Android way of building UI, but with Swift. This will work good with #1.

4) Should Swift try to mimick the iOS MVC model and UI component as much as possible. This will probably be better with #2.


My sense is that the lowest hanging fruit (which still require quite a bit of work) is Swift compile to Dalvik bytecode (#1) with full Dalvik component/library access and be a wrapper on Android UI component and constructs (#2). Now, the question is will this be worth all of the effort.

Quora

Silver - Swift, now also on .NET, Java and Android.
Silver is a free implementation of Apple's Swift programming language.

With Silver, you can use Swift to write code directly against the .NET, Java, Android and Cocoa APIs. And you can also share a lot of non-UI code between platforms.

Built on over ten years of solid compiler knowledge and technology, Silver is a truly native Swift compiler for the .NET CLR, the Java/Android JVM and the Cocoa runtime.

Silver supports three platforms, but is decidedly not cross-platform, focusing on letting you leverage the Swift language natively for each individual platform, rather than encouraging mediocre cross-platform apps. With Silver, you can share your language and tool expertise, and you can share a lot of back-end business logic code – but you will use it to write apps targeted at each platform individually. Why? Because that's how great apps are made.

Elements

Comments

Most Favorite Posts

Server-driven UI (SDUI): Meet Zalandos AppCraft and AirBnB Lona

A short WTF: Joe Birch:  SERVER DRIVEN UI, PART 1: THE CONCEPT Zalando seems to follow the SDUI principle as well - defining a common design language and construct the screens on the backend while displaying them natively on the clients. They even go one step further; they implemented a mighty toolset to enable non-technical stakeholders to define their own native app screens Compass: Web tooling to create screens and bind data Beetroot: Backend service that combines the screen layout definition with the data Lapis/Golem: iOS/Android UI render engines Crazy cool! Good job, guys (when you do an open-source release?) To even move faster a Flutter based UI render engine implementation was great! See also AirBnB Lona SDUI approach Building a Visual Language Why Dropbox sunsetted its universal C++ mobile project and AirBnB its React Native implementation

FF Chartwell: Defining pie chart, bar charts and many others via vector font!

  With FF Chartwell you can define Charts via OpenType font, and transform a string, e.g. " 60+ 30 + 10 " into a Pie Chart 60%-30%-10% including color support (not only b/w!) without rendering anything: directly via font without using any images! Check this out: FontBlog FF Chartwell So great!

Apple Sneaks A Big Change Into iOS 5: Phasing Out Developer Access To The UDID

Apple is making a lot of big changes to its mobile operating system with iOS 5, which is dribbling out in betas for developers ahead of a general release later this year. But there is one big change some developers are just starting to take notice of that Apple isn’t talking about that much. In a recent update to the documentation for iOS 5 (which is only available to registered Apple developers, but a copy was forwarded to me), Apple notes that it will be phasing out access to the unique device identifier, or UDID, on iOS devices such as iPhones and iPads. TechCrunch Solution A: UIDevice-with-UniqueIdentifier-for-iOS-5 Brings back the unique identifier support under iOS 5, it uses the device's mac address in combination with the bundle identifier to generate a new hashed unique identifier. gekitz GitHub Alternate Solution B: Appsfire Announces Open Source UDID Replacement For iOS: OpenUDID It is based on the NSProcessInfo (see globallyUniqueString), but may change ...

Writing High-Performance Swift Code

Enabling Optimizations Whole Module Optimizations (WMO) Reducing Dynamic Dispatch Dynamic Dispatch Advice: Use 'final' when you know the declaration does not need to be overridden Advice: Use 'private' and 'fileprivate' when declaration does not need to be accessed outside of file Advice: If WMO is enabled, use 'internal' when a declaration does not need to be accessed outside of module Using Container Types Efficiently Advice: Use value types in Array Advice: Use ContiguousArray with reference types when NSArray bridging is unnecessary Advice: Use inplace mutation instead of object-reassignment Wrapping operations Advice: Use wrapping integer arithmetic when you can prove that overflow cannot occur Generics Advice: Put generic declarations in the same module where they are used The cost of large Swift values Advice: Use copy-on-write semantics for large values Unsafe code Advice: Use unmanaged references to avoid reference counting overhead Protocols Ad...

iOS In-App Browser JavaScript injections to spy on user behaviour on 3rd party websites

 iOS Privacy: Instagram and Facebook can track anything you do on any website in their in-app browser The iOS Instagram and Facebook app render all third party links and ads within their app using a custom in-app browser. This causes various risks for the user, with the host app being able to track every single interaction with external websites, from all form inputs like passwords and addresses, to every single tap. KrauseFX

Starting UIAutomation via command line

You can do it now, starting with XCode 4.2 for iOS5 beta 4 From command line, you can run instruments pointing to the automation template and specify as environment variables the test script you want to execute and destination path for results: instruments -w device_id -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate application -e UIASCRIPT script -e UIARESULTSPATH results path DevForums Apple instruments Mac OS X Developer Tools Manual Page

10 Coolest Keyboard Shortcuts You Never Knew About

Keyboard shortcuts are the lifeblood of many productive Mac users. Not only can keyboard shortcuts make for a nicer user experience and cut down on the time needed to do a task, they can also just be plain cool. Mac OS X has many shortcuts ready and willing to do your bidding, but also has many hidden and unknown shortcuts. That's why we've compiled a list of 10 of the coolest keyboard shortcuts you never knew about. MacLife