A few weeks ago I told about a question I was asked, which led to my post about full-stack developers. And then my post on user interface options for Java developers.
Today I want to finish off the discussion about cross-platform development with a look at some of the options for mobile app development.
The Client Wants Android
Let’s say you’re approached by a prospective client (or instructed by your boss) to develop an exciting new super-duper mobile application with the stated requirement to run on Android devices.
You do the barest minimum research to find out that Android Studio is the official IDE for Android. So you download and install it, and get busy developing the app. Almost immediately you have to make a decision about what language to use: Java or Kotlin.
You already program in Java, so it’s probably your first choice. But with a bit of more research, you discover that Google now recommends that all new Android development should be done in Kotlin.
Kotlin is a cross-platform, general-purpose programming language. It was originally developed by JetBrains (the developers of IntelliJ IDEA and Android Studio). Kotlin was designed to interoperate fully with Java, but be easier to use than Java. Kotlin looks a lot like Java, so will be easy to learn. It also has type inference that allows more concise language syntax. The Kotlin compiler can compile to either Java bytecode, JavaScript or Native (which is used by Apple’s Xcode IDE). The JVM version of Kotlin’s standard library depends on the Java class library. As a bonus, Kotlin is now open-source too.
Hmmm, decisions, decisions… But your client just needs the app on Android, so you decide to stick with Java.
The Client Expands the Scope to iOS…
A few meetings and demos later, your client asks a simple question, “Can this app run on the iPhone?” “No”, you say. The client makes noises that it’s a really important new requirement, and implies that they’ll have to find other developers to do it if you can’t. Whoops, mad internal panic! “Sure!”, you say, “We can do it. We’ll just need a bit more time.”
In countries like the USA and UK, Android and iOS have roughly equal market share. This means that most mobile apps have to be developed on both platforms, or you’ll risk losing potential clients. To create apps for both platforms, you’ll have to choose between two options: either build two separate native applications or one cross-platform application which will run on both iOS and Android.
Now what? Java doesn’t run on iOS, and in any event, because the two platform APIs are radically different, the whole program will have to be recreated from scratch.
You really don’t want to maintain two sets of code – one set is hard enough, so you decide to look for another development framework.
Kotlin would have given you a head-start, because you would have been able to reuse much of your business logic, database code, analytics and algorithms. By using Kotlin Multiplatform Mobile you would only have had to implement the native user interface (UI) code specific to the Android and iOS devices. So close, yet so far out of reach now because of your initial language choice.
You start looking for other Java-based alternatives. A web search turns up Gluon Mobile. With Gluon Mobile you can build and deploy an application in Java for Android and iOS using the same APIs. Gluon is based on JavaFX, and allows you to create high performance, cloud connected mobile apps from a single Java code base. It isn’t open source and carries an annual right-to-use subscription fee. It definitely ticks the right boxes for Android and iOS, but it would require a total rewrite of your existing Android code. Sigh…
The Client Expands the Scope to Windows, MacOS and Linux…
While you’re still evaluating these alternatives, your client phones and says that they also really need the application to run on Windows, MacOS and Linux. Arrgghh!!
You widen your Google search and libGDX pops up. LibGDX is a cross-platform Java game development framework based on OpenGL. It works on Android, iOS, macOS, Windows, Linux and browsers. Sounds perfect! But wait, it’s a games library, and you’re not developing a game. You can’t understand half of what the website says – meshes, textures, shaders, sprites, orthographic cameras, 2D and 3D APIs, particle systems. Where are the buttons? Labels? Textboxes? Yes, they are there, but they’re oriented towards a game UI, rather than a standard platform look-and-feel like Material Design (Android) or Cupertino (iOS).
Great for a graphical game, probably not so good for your particular business-related mobile app. And it would demand another total code rewrite. Will it ever end?
Xamarin appears next in your search results. Xamarin is another free, open-source platform for building cross-platform applications. You can develop Android, iOS, macOS and Windows apps with Xamarin. Excellent! But wait, now you’ll have to code in C# using the .NET libraries. The entire app will have to be rewritten from the ground up using C# – the UIs, the business logic, data access code, native API access, everything. There’s a promise of a “single” codebase, but it’s limited to about 75% of your code being shared across these platforms.
How about Basic? Anywhere Software has a B4X suite of products that support more platforms than you currently need: Android, iOS, Windows, macOS, Linux, Raspberry Pi, Arduino and ESP8266/ESP32 system-on-chip devices (for IoT). The B4X programming language is a modern version of Visual Basic. Compiled applications are 100% native without any dependencies.
B4A is used to develop Android apps. Together with B4i you can develop applications for both Android and iOS. B4J apps can run on Windows, Mac, Linux and ARM boards (such as Raspberry Pi). B4R is used to create native Arduino, ESP8266 and ESP32 programs. B4A, B4J and B4R are 100% free. Only B4i needs to be purchased.
All this and you only have to learn Basic! Nothing wrong with Basic – Visual Basic had millions of adherents in its day, and was really easy to learn and code. A bit of a jump if you only know Java, but nothing that a bright programmer can’t handle, right? Downsides include a totally different syntax; the language is only object-aware, rather than fully object-oriented; properties instead of getters and setters; and more new language tricks to learn.
Delphi anyone? Using Delphi allows you to develop iOS, Android, Windows and macOS apps from a single Delphi codebase. The latest version supports Windows 11, macOS 12, iOS 15 and Android 12. The Delphi Community Edition can be downloaded for free, but is still a full-featured IDE. It only has a limited commercial use license, but commercial licenses are available for the more premium products.
All this and you only have to learn Delphi! Very similar comments here as for a Basic – a totally different language to Java which you’ll have to learn, with its own APIs and ways of thinking.
How about Flutter? Flutter is an open source framework developed by Google. It allows you to build natively compiled, multi-platform apps from a single codebase. Flutter supports seven different platforms: Android, iOS, Windows, macOS, Linux, browsers, and Raspberry Pi. Flutter code compiles to ARM or Intel machine code as well as JavaScript. Up to 90% of the code can be put into a single codebase and be shareable across platforms.
Flutter uses the Dart programming language. Dart looks a lot like a cross between Java and Kotlin, so will also be really easy to learn. You can experiment with Dart in the browser using DartPad, a web-based Dart execution environment.
So far Flutter and Dart sound like an awesome combination. If you move to Flutter you’ll have to rewrite your existing Java code, but every development environment you’ve looked at so far has that requirement.
Salient Points
What have you learnt from this? Don’t decide on a language and a technology stack before you know what your client’s needs and objectives actually are. Ask them lots of questions to formalise the scope and the possible future paths. This will help you select the best-suited technology.
Before you start developing a mobile app (actually, any app!), you need to know the business goals, target market, requirements and features. Only then you’ll be able to decide on the best language and toolkit for developing that exciting new super-duper app.
Conclusion (IMO)
In my opinion, unfortunately Java isn’t the best language to use when doing cross-platform mobile app development.
I say “unfortunately” because I’ve been teaching Java since 1996 when Java was still shiny new and on version 1.0. For me it’s a great language with an extensive infrastructure and a vast selection of frameworks.
It saddens me that Java-specific cross-platform mobile app development has been stunted by the legal issues surrounding Java. So much so that it’s easier for companies to develop new languages such as Kotlin and Dart than to try expand the usage of Java within the mobile app development space.
So, what do you think? I can’t wait to hear your opinions on this topic.
Stay safe, and I’ll see you next week!
4 thoughts on “Cross-Platform Mobile App Development for Java Developers”
Great Article Lewis
For me Flutter was the obvious choice after some investigation and playing around with Flutter and React native.
I have developed numerous android apps and suddenly we have the same issue that we need to expand to IOS.
The reality was that it does not matter how you look at it you will have to learn a new language either Swift or Java script or Dart.
Looking at the github pulls it seems that Flutter is taking off in a very positive way and with its built in packages the development time is largely reduced.
When you work with flutter for a while you realize how much boilerplate code native Android requires to accomplish the same thing.
For now our company is investing in Flutter to accomplish the cross platform option.
Thanks for the compliment about the article, and thanks for taking the time to send your comment! Much appreciated!
I’ve been teaching Android development with Java for a good number of years now driven by client demand. I’ve never been a big fan of the Android API, but that’s all we had to develop Android apps with.
We’ve never had sufficient client demand to teach any iOS courses, but it bothered me that a programmer would have to learn an entirely different language and API to redevelop the same applications.
I thought the mobile app industry was on the right track when I first came across Xamarin. Here’s a development system that we could use to target both Android and iOS with (largely) one code base, at the expense of learning another language and API. But what about Windows and Linux and all the other possible platforms.
Now the industry ha become even more mature with the alternatives I mentioned in my post (and more besides).
When I saw Flutter, I was very impressed by the Dart language and the Flutter API, and I’m steadily getting more impressed. Thanks for the feedback that your company is investing in Flutter. At least I know I’m not alone. 😉
Hi Lewis.
I like your logical analysis.
I started with Turbo Pascal, Turbo Pascal for Windows, Delphi 1-7, VB6,C,C++ and last Java (~10 Years).
I use java most of the time, but all my Utils I do in Lazarus. I run my utils on linux and window$.
What I love about the Lazarus/FreePascal binaries is that it is not linked to glibc, so I don’t have to recompile every time glibc is updated !
I created a utility that stays on my task bar back in 2006 and just kept on using it on linux and windows until 32 bit was not supported any more.
Only then did I recompile it.
Regards
RudieD
Nice article Lewis,
You left off Codename One though, it would be the most obvious choice in the situation you described above. Its open-source and compiles Java or Kotlin to native code for Android, iOS, UWP, JS etc with 100% code reuse.