Dec 4, 2023

Making android development less painful

Android development has always been challenging and frustrating right from start. However things are looking better now.

Making android development less painful

I had started android development in 2012. I have always remembered it as a painful experience for number of reasons. First problem with Android was of version fragmentation. There were too many android OS versions that were active and every one of them had improvements that were not very consistent with the previous versions so in order to give more seamless experience you had to rely on support libraries. Interestingly, there were multiple versions of support libraries as well.

The problem was compounded by documentation which often did not offer the right solutions. For example for a long time Android's official documentation suggested that you use AsyncTask for internet IO. In reality this was a horrible advice because AsyncTasks are not really meant for this sort of internet IO and there could only be two AsyncTasks running at the same time.

UI and the code that controls UI was separated using XML files for layout and Java Activity or Fragment classes that wired up events to the UI represented in XML. Again here there were countless problems. Android supported different themes which were essentially all over the place. How do you show a top bar ? There were far too many ways to achieve that each way inconsistent with some theme or another.

None of these problems were insurmountable. In fact android was getting better with each version. The problem was that the developer experience was getting terrible.

Build system pains

Android opted for Gradle to manage its build process and it was a nightmare and it remains so. I have many apps that are live occasionally I try to rebuild them and things fall apart for no good reason. It is hard to debug and it is hard to understand what exactly that build.gradle does. It takes a while to understand what all is happening there.

Then you run into an error where the android's virtual machine supported only max of 65K java methods. Then constantly changing gradle syntax where you had to replace "compile" with "implementation" and several other changes.

If that was not enough you had to manually configure to strip out unused code from the app to make the APK smaller.

Compared to iOS

Compared to all this Apple's developer ecosystem was doing much better. The Objective C was a painful language to learn. But move to Swift was very pleasant. Building UI was simpler though for some people who prefer more declarative syntax it was a bit of magic. But the build process worked pretty well and you could make a hello world app and upload it to app store in a day.

Architecture

My biggest pain with Android development however was the lack of standard best practices on how you should architect your complex app. How do I split my UI components ? How do I separate network communication from rest of the application logic ? How do I make it fault tolerant ? Which network library is ideal ? How do I manage different levels of persistence ? How to handle notifications ?

There was no real recommendation from Google on how to achieve this objectives and if you are a self learner than this was terrible because Google's official documentation always recommended the wrong ways of doing things because it was the simpler way to do things.

What is modern android ?

In year 2023, Android development has substantially improved and has become much easier [1]. The aspects that make is easier are as follows.

Kotlin

Kotlin is a language developed not by Google but by Jetbrains which is the company behind the popular IDE IntelliJ. Since 2019 it was the preferred language of Android development by Google. It find this surprising because Google is home to another excellent language called Dart which isa already used for front end development in Flutter. It had similar features as Kotlin (though not interoperable with Java).

But in any case Kotlin is definitely easy to learn and easy to write language compared to Java which avoids needless verbosity without losing expressive power of Java. It certainly matches up with Apple's Swift.

Compose

I have done a lot of Flutter and React development and I absolutely loved their ways of building UI. You define UI in code by composing a complex UI component from a simpler component. Unlike in Android where you have no clue what the UI looks like when you look at the Java code, Flutter and React was much more easy to write and read.

Google has finally brought that same paradigm to Android development through its Compose library.

@Composable
fun Greeting(names: List<String>) {
    for (name in names) {
        Text("Hello $name")
    }
}

This simple code create a UI where you can list several Text elements. Imagine writing he same in Java. It would be a LOT of code.

In my opinion Google might have actually taken Flutter's way of building UI in designing this Compose library and it has certainly simplified a lot of work for us.

Jetpack

Jetpack is basically collection of libraries that replace all the support libraries and provide you with a new sent of libraries which you can use and rely upon as the OS improves because unlike the appcompat libraries of past, Jetpack will give you more consistent and reliable interface for doing things like creating Activities, Fragments, Databindings and so on.

Better backward compatibility

Google has worked very hard to make life easier for us to move on to a new Android version from an older one. Yes, this is not exactly painless and still we might have to fix few things manually but unlike in past, we have better tooling around achieving this.

Architectural recommendations

What however has made the greatest difference in my opinion is that Google has finally started actually recommending how you build your apps instead of giving you documentation around disjoint OS features. [2] This has resulted into people reading Google's sample code and using it to build their own apps which creates familiar and better patterns everywhere.

Their sample apps like Sunflower app and Now in Android Apps are beautiful and actually properly built instead of being just some ill maintained example apps like in past.

Android studio has gotten better

Android studio has been around for a long time but only in last 2 years it looks as solid as Apple's XCode. It has seen several performance improvements and better tooling, especially when it comes to building UI.

Android now is at more places than before

Android today not only powers smartphones but it also powers cars through Android Auto, Televisions through Android TV and many other different form factors. All these tools and improvements makes life easier not just for app developers but also developers targeting television and automobiles.

Conclusion

I will be spending some time on this blog to take you through a journey of building some excellent fun Android apps and give you detailed tutorials.

[1] https://developer.android.com/modern-android-development

[2] https://developer.android.com/topic/architecture

Continue Reading
Learn about other front end technologies

Learn about other front end technologies

We are partnering with Frontendeng.dev to cross promote the content around front end engineering.

Published Dec 12, 2023

Android paired with Windows Laptops

Android paired with Windows Laptops

The new trend is to build Android and Windows Laptop into one hardware.

Published Jan 11, 2024

What are co-routines in Kotlin ? Kotlin for Android Part -2

What are co-routines in Kotlin ? Kotlin for Android Part -2

In this part we will learn about Kotlin's co-routines. It is an important concurrency design pattern that is extremely useful when designing asynchronous programs.

Published Dec 31, 2023

Backends for your Android App

Backends for your Android App

In this article, we will explore the various options available for app developers who are primarily focused on building an app backend.

Published Jan 1, 2024

Google Flutter vs Android Jetpack Compose : A detailed comparison

Google Flutter vs Android Jetpack Compose : A detailed comparison

Flutter code looks remarkably similar to Android Jetpack Compose. However which one of them is better ? We find out in this article.

Published Jan 11, 2024

Minimal starting template for Android Compose

Minimal starting template for Android Compose

Find a simple minimal code to open an app with top and bottom bar. Find full code on https://github.com/Wiseland-Inc/dev.androidauthority.app

Published Dec 11, 2023

Spring Boot for App Backends

Spring Boot for App Backends

Simple spring boot template to deploy on Google Cloud and to be used as your app backend.

Published Jan 6, 2024

Learning Kotlin for Android development - Part 1

Learning Kotlin for Android development - Part 1

A guide focused on teaching you basics of Kotlin just for Android development.

Published Dec 7, 2023

Understanding Layouts in Android Compose

Understanding Layouts in Android Compose

A very quick tutorial on compose and layouts.

Published Dec 10, 2023

What are adaptive android apps ?

What are adaptive android apps ?

Adaptive apps are app equivalent of responsive web apps. Apps that resize to give good user experience across several devices.

Published Dec 9, 2023