Mobile
Article
By Chris Ward

Java-Free Android

By Chris Ward

Android finds itself in interesting times. Google has begun creating it’s own ‘premium’ versions of the operating system (OS), Cyanogen have ceased development, and many feel that Android will change name or shape in the near future.

As the future of the OS remains uncertain, so does the language that developers use to develop for the platform. Traditionally developers have written apps for Android in Java, a language with a long established history and ecosystem, but that has always felt forced upon Android, lacking the most up to date features, and unwieldy for developers who come from different language backgrounds.

In this article I will round up some of the likely contenders and see how easy, realistic and plausible it will be for them to replace the Java behemoth. The added bonus for some of these languages, is that you can often use them to target other mobile platforms.

No Webviews allowed

A long term solution for developers has been to use different techniques to turn JavaScript and HTML into pseudo applications. I wont include any of these hybrid options in this round up such as React Native, Cordova or NativeScript. I don’t want to begin flame wars on native vs hybrid app development, but in this article I am only interested in covering languages that could become ‘native’ code.

Enter the NDK

Google took an interesting decision when deciding that Java would be the programming language to create apps for Android. Whilst it’s portable and popular, it also restricts developers as there is no official support for using more efficient languages such as C or C++.

The Native Development Kit (NDK) is a workaround for this restriction, adding support for you to access certain hardware features with these languages. Intended as a way for developers to reuse legacy libraries that use C/C++, it’s also a common way to use other languages on Android. Many of the examples I will present take this path, using the NDK to compile code to C/C++. It’s not just an excuse for experimentation, but also opens up Android to a larger world of developers and libraries.

To use Android APIs and libraries, a developer will typically have to ‘bind’ the C/C++ through wrapper code, and access the functionality through this intermediary. This isn’t as bad as it sounds and requires minimal Java code.

In the past the NDK was best avoided, but in recent years it has become better to use and more performant. In certain use cases (especially games) it’s more performant than Java, but this is still advanced territory with pitfalls along the way.

Ready for adventure? Then let’s begin.

C, C++ and C

A you might have guessed, if you want to code C and C++ for Android, then Android Studio already supports it thanks to tooling borrowed from CLion, an IDE also created by the makers of the core of Android Studio, JetBrains.

If you want to know more about using C/C++ code with Android, then I recommend this article to get you started.

Xamarin

Originally called Mono, and now owned by Microsoft, Xamarin allows you to use C# across multiple platforms, including Android. Again, under the hood it uses NDK to compile the C#, but gives you access to most native components and APIs. The pricing model can be confusing as now Xamarin is part of Visual Studio pricing, which means you pay for support, and infrastructure support, but the IDE is free.

If you like C# (and every C# developer I have ever spoken to loves the language), then it’s a good option for you.

Kotlin

Kotlin is an interesting proposition, it’s one of the most accessible languages in Android development – and the most likely to replace Java. It’s created by JetBrains, who make the underpinnings of Android Studio and is interoperable with Java, meaning you also get access to the official Android libraries.

It works well with Android Studio and aims to be familiar to Java developers, whilst bringing the benefits of other modern languages. You can also compile it to JavaScript code, which makes it an even more interesting option for those of you creating multi-platform applications.

Find out more on the project’s website.

--ADVERTISEMENT--

Go Lang

Go is relative newcomer (2009) born out of Google, so many anticipated that it would become a viable Android development option. It posses features popular with modern application developers such as the ability to run instances of an application (and individual parts of) simultaneously. It’s fast, and stripped of a lot of the extraneous baggage that older languages bring with them. This feature set has made it popular with applications such as Docker, but I wonder if they are so relevant for mobile app development.

Still, there are packages available that support Android (and iOS) development, which are easy to integrate into your apps and ideal for middleware or backend services to serve the app interface.

First install GoLang and then the GoMobile tools and initialize them. After this you have the choice of building an isolated application that suits the purposes I mentioned above, or you bind sections of the Go code to native Java code.

Want to know more? Then read the project’s documentation and make sure you follow every step carefully, much like compiling other languages, Go requires certain connections and tools to be setup correctly on your system.

Dart.js

Don’t let the name deceive you, whilst Dart has elements of JavaScript within it, the language is compiled, and runs it its own virtual machine (VM), much like Java. Dart is another recent Google invention (2011), and after a period out of the limelight, has resurfaced as a likely-if-it-happens replacement for Java. It will appeal to any of you that come from JavaScript backgrounds, keen to move into C-style languages as it contains elements of both.

For mobile development, a set of extensions and tooling exists called Flutter that takes interesting and different approaches. It doesn’t use native widgets and components, or a web view. Instead Flutter uses it’s own methods to render screen elements and run your code. This introduces complexity to the project (not necessarily the language), but also makes it a more obvious drop-in replacement.

Flutter have aimed to make life as easy as possible for you with plugins and tooling for Atom and IntelliJ. To get started, Install Dart.js, then Flutter and then read the project’s guide to start your first project.

Swift

Swift has its origins with Apple, and is now a language of choice for many iOS developers, so why would you consider it for Android development? The language went open source in December 2015 and enjoys solid Linux support, so developers wondered how plausible it would be to port to Android, with its Linux kernel-esque core.

Pull requests and documentation in the Swift project and a plethora of blog posts have stoked excitement at the potential. There’s a document lurking in the Swift repository, that involves following the traditional steps of using NDK to compile the Swift code to byte code that Android can understand. Read through that document and you will see that there are a lot of complex and specific steps, and in my past experience, changes to the NDK from Google frequently break this process. Even when you do get this working, you will be stuck with an app that can’t interact with any Android libraries (yet).

Despite this fraught process, developers are still determined to find a way to make Swift work on Android and I recommend you read this series of blog posts from a group of developers who got a Swift app into the Google play store.

Elements Compiler

RemObjects make the elements series of tools that are something of a hybrid between the offerings from Xamarin and JetBrains. They have a suite of tools that allow you to develop in a variety of languages for cross-platform targets. From an Android perspective you can use Silver to write Swift (yes indeed!) with access to native APIs. The IDE isn’t as polished as other solutions and I have had mixed experience getting it working, but it’s a compelling option if it works for you.

Rust

Rust originates from Mozilla and has been growing in popularity for the past years (It won most loved programming language of 2016 in the Stack Overflow Developer Survey). Designed for more complex systems to run multiple processes at the same time, it’s not primarily suited for mobile apps, but this hasn’t stopped people trying.

As Rust is a compiled language, getting your Rust application to run on Android is a similar path to the other options in this article, but the path is less well-trodden. I found the project and instructions here the most useful, and the process will be familiar to any of you who have tried getting other compiled languages to run on Android.

Caffeine-free future

Who knows what Google (and others) have in mind for the future of Android development, but after reading this article and a little experimentation I hope you are all better prepared for whatever that future might be.

Below are tutorials we wrote to help you start preparing!

Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account