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.


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.


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.



Most Favorite Posts

Pattern: Riblets vs. VIPER

Engineering the architecture behind Uber's new rider app

Not being held back by our extensive codebase and previous design choices gave us the freedom where we otherwise would have made compromises. The outcome is the sleek new app you see today, which implements a new mobile architecture across both iOS and Android. Read on to learn why we felt the need to create this new architecture pattern, called Riblets, and how it helps us reach our goals.

The platforms share:

Core architectureClass namesInheritance relationships between business logic unitsHow business logic is dividedPlugin points (names, existence, structure, etc.)Reactive programming chainsUnified platform components
Each Riblet is made up of one Router, Interactor, and Builder with its Component (hence the name), and optional Presenters and Views. The Router and Interactor handle the business logic, while the Presenter and View handle the view logic.


How to link to TestFlight App in iOS

There are two things you need to do. First, check to see if TestFlight is installed. Then create a new link to your app.

NSURL *customAppURL = [NSURL URLWithString:@"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {

    // TestFlight is installed

    // Special link that includes the app's Apple ID
    customAppURL = [NSURL URLWithString:@""]; 
    [[UIApplication sharedApplication] openURL:customAppURL];

This special URL will be opened directly in TestFlight.

Finally, if you are using iOS 9 (or later), you need to make an addition to your Info.plist to get the canOpenURL: method to work.

If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the LSApplicationQueriesSchemes array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it …

Implementing UI tests on iOS and Android using screenshot comparison tools

Have you ever thought when writing or maintaining UI tests, there must be a better way?

Take a look at screenshot tests provided by Google Firebase and Facebook:

A "snapshot test case" takes a configured UIView or CALayer and uses the renderInContext: method to get an image snapshot of its contents. It compares this snapshot to a "reference image" stored in your source code repository and fails the test if the two images don't match.

GitHub Facebook

Testing rendering for your Android app is hard. How do you prevent visual regressions in paddings and margins and colors from creeping in?
Iterating on UI code is hard. How do you quickly verify that your layout or view changes work correctly in all configurations?

screenshot-tests-for-android can solve these problems by providing a test framework that checks for visual differences across changes.

GitHub Facebook

Google Firebase Test Lab
Test Lab lets you run Espresso, …

iOS 7 Blur Effect

Combining a strong colour with a blurred and translucent UINavigationBar in iOS 7.

// cheers to @stroughtonsmith for helping out with this one
UIColor *barColour = [UIColor colorWithRed:0.13f green:0.14f blue:0.15f alpha:1.00f];

UIView *colourView = [[UIView alloc] initWithFrame:CGRectMake(0.f, -20.f, 320.f, 64.f)];
colourView.opaque = NO;
colourView.alpha = .7f;
colourView.backgroundColor = barColour;

self.navigationBar.barTintColor = barColour;

[self.navigationBar.layer insertSublayer:colourView.layer atIndex:1];

GitHub Gist
See also

And also
myView.backgroundColor = [UIColor clearColor];
UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:myView.frame];
bgToolbar.barStyle = UIBarStyleDefault;
[myView.superview insertSubview:bgToolbar belowSubview:myView];

Why bother replicating the effect? Just draw a UIToolbar behind your view.

Alpha Apps vs. App Unbundling

Alpha Apps
Die chinesische App WeChat geht noch weiter: Neben einem Messenger, vergleichbar mit WhatsApp, bietet sie einen Lieferdienst à la Lieferando, die Möglichkeit etwa das eigene Konto zu checken (wie sonst bei der Bank-App) und gleichzeitig die Chance etwa Promis zu folgen, wie es Twitter bietet.

Solche Alpha-Apps können dadurch verschiedene Aspekte und Möglichkeiten des Internets verbinden und werden so zum idealen Zugangsportal zum Netz – so wie traditionell der Browser am Computer. Den Tod des Browsers bedeutet das aber noch lange nicht.

Der Browser ist tot, es lebe der Browser!
Wirtschafts Woche

App Unbundling Unbundling steht für das Unterteilen von Apps oder verschiedener Funktionen in mehrere, eigenständige Applikationen.

Aber nicht jede Unbundling Aktion wird positiv von Usern aufgenommen. Facebook Messenger erhielt hunderte miese Bewertungen in den App Stores, denn viele User fühlen sich von Facebook grundlos gezwungen eine zusätzliche App herunterzuladen. Das Fazit: was…

Apps vs. Web

Eines scheint klar: Mobil büßt er gegenüber den Softwareprogrammen aus dem App-Store Nutzer ein. „Mittlerweile spielen Apps die wichtigste Rolle für den User – oder sie werden sie zumindest sehr bald spielen“, sagt Jan Wolter, Geschäftsführer von Applause EU.

Apps bieten also im Gegensatz zum Browser Schnelligkeit gepaart mit Einfachheit und Bequemlichkeit. Sie öffnen zwar nicht die Welt ins gesamte World Wide Web, wie es der Browser kann, aber sie öffnen die Welt, die man möchte, wenn man ihr Icon auf dem Tablet anklickt.

Die chinesische App WeChat geht noch weiter: Neben einem Messenger, vergleichbar mit WhatsApp, bietet sie einen Lieferdienst à la Lieferando, die Möglichkeit etwa das eigene Konto zu checken (wie sonst bei der Bank-App) und gleichzeitig die Chance etwa Promis zu folgen, wie es Twitter bietet.

Solche Alpha-Apps können dadurch verschiedene Aspekte und Möglichkeiten des Internets verbinden und werden so zum idealen Zugangsportal zum Netz – so wie traditionell der Brows…

Why Core ML will not work for your app (most likely)

While the buzz around newly released Apple framework is loud, I want to explain several things, that may not be obvious for those who are new to machine learning (ML).
Core ML is not a machine learning framework.Core ML supports only two types of ML.If your models are proprietary or contain sensitive information, you can’t use CoreML.Core ML doesn’t solve the privacy concerns.Core ML doesn’t compress models.Core ML is not the only way to do machine learning on iOS.
Learn Machine Learning, not Core ML.
Impervious Invisibility

Google’s AutoML lets you train custom machine learning models without having to code