Home Android & Kotlin Books Android Apprentice

28
Android Fragmentation and Support Libraries Written by Darryl Bayliss

Heads up... You're reading this book for free, with parts of this chapter shown beyond this point as scrambled text.

You can unlock the rest of this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

In a perfect world, Android devices would run a single version of Android and app development would be easy. As it turns out, the world isn’t perfect.

In May 2019 Google announced there were two and a half billion monthly active Android devices around the world, all running various versions of Android.

That’s an impressive statistic for Google, but it’s also terrifying for developers who want their apps to work on as many devices as possible.

This chapter, however, is aimed at helping to put you at ease. Not only does it explore the history of Android, it explains how developers can target as many versions of Android as possible. Within its pages, you’ll learn:

  • What problems Android faces from fragmentation and why they exist.
  • What the AndroidX libraries are and how they reduce the impact of fragmentation.
  • How an app you created earlier in this book uses the AndroidX Libraries as a way to be backwards compatible.

Android: An open operating system

To understand where the fragmentation problem originates, it’s important to understand how Android came to be the most popular operating system on the planet.

Google originally acquired Android by buying a company named Android Inc in 2005. Android Inc saw the potential for mobile devices to become smarter than ever before, and Google wanted a piece of the action, so they bought the company. Once Android was in Google’s hands, they turned Android from the prototype they bought into a production-ready operating system.

Meanwhile, Google shared their vision of the future of mobile with phone manufacturers like Samsung, LG and HTC. What Google offered to phone manufacturers was a stable operating system, and one that could be altered to work for a particular manufacturer’s needs.

For Google, it was a way to reach users like never before. For phone manufacturers, it was a way of keeping up with the competition. The approach towards openness ultimately convinced phone manufacturers to adopt Android as the operating system for their devices.

When Google publicly announced Android in November 2007, it also announced the creation of the Open Handset Alliance (http://www.openhandsetalliance.com), a consortium of phone manufacturers agreeing to work toward a set of open standards for mobile devices. Those standards materialized in the form of Android.

To ensure these standards were openly available, the Android Open Source Project (https://source.android.com) was created, which allows anyone to download and contribute to the Android Operating System.

How Android Fragmented

As years went by, devices needed updates for their Android OS. However, many devices didn’t receive updates for months at a time. This is because phone manufacturers had to take time to test updated versions of Android and synchronize those with their own in-house changes for their particular flavors of Android.

The AndroidX Libraries

To ensure developers are not held back by delayed Android updates, the engineering teams at Google introduced the Android Compatibility Library in 2011. This library aimed to ensure Android was easy to develop for across multiple versions of the operating system.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.preference:preference:1.1.0'
    implementation "androidx.cardview:cardview:1.0.0"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

package androidx.appcompat.app;

package androidx.fragment.app;

package aandroidx.recyclerview.widget;

Reducing the impact of fragmentation in your app

Although fragmentation is a real problem for Android, the engineering teams at Google provide a way for developers to avoid its effects, ensuring apps can reach as many users and devices as possible.

Where to go from here?

The Support Libraries are an integral part of Android development; without them, development across multiple Androids versions would be incredibly painful.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.

Have feedback to share about the online reading experience? If you have feedback about the UI, UX, highlighting, or other features of our online readers, you can send them to the design team with the form below:

© 2021 Razeware LLC

You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

Unlock Now

To highlight or take notes, you’ll need to own this book in a subscription or purchased by itself.