What is AndroidX?

What is AndroidX?

Introduction

AndroidX represents a new approach to how Google is organizing its support libraries. As you know, there's many different android.support libraries and many often don't play nice with one another. Overall it's a very confusing and un-intuitive documentation design. Some of the most common examples that you probably use it almost every Android project are:

  • com.android.support:appcompat-v7
  • com.android.support:recyclerview-v7
  • com.android.support:design

Here's what those libraries will look like once you've refactored to AndroidX:

  • androidx.appcompat:appcompat
  • androidx.recyclerview:recyclerview
  • com.google.android.material:material

You can find the complete mapping here with the rest of the libraries.


The com.google.android.material: material library is particularly interesting. Earlier in 2018 Google launched a new material design website, Material.io. MaterialDesign.io is technically the 'new' documentation for the com.google.android.material library.


On Material.io you'll find the newest templates, designs, and best-practices when it comes to material design on Android. I have to say, the documentation on Material.io is a huge step up from the current android documentation.

Should I Migrate to AndroidX?

At this point you probably have a few questions:

  1. Is AndroidX backwards compatible with earlier versions of Android?
  2. Is it going to take me a long time to convert existing projects?
  3. Is there a way I can avoid using AndroidX because I'm lazy and don't like to learn new things?

I will answer all of these.

Q. Is AndroidX backwards compatible with earlier versions of Android?

The short answer is yes.

The new AndroidX naming design is just that, a design. The support libraries are built for backwards compatibility and so are the AndroidX libraries. You can think of the AndroidX libraries as a continuation of the support libraries, but with a more intuitive naming convention.

Q. Is it going to take me a long time to convert existing projects?

Not if you update your Android Studio to version 3.+. I've also included steps on how to do that in this blog post. See steps.

Q. Can I Avoid Using AndroidX? (I'm Lazy)

For now, yes. I'm guessing this feature is going to be deprecated very soon, but at the time I'm writing this blog post there is a way to continue using the old support libraries with the new features from the AndroidX libraries.


Instead of using the new AndroidX naming, all you need to do is use the alpha version of the support libraries. Here are some examples:

com.android.support:support-compat:28.0.0-alpha1

com.android.support:recyclerview-v7:28.0.0-alpha1


Step 1. Updating to Android Studio 3.2

In Android studio 3.2 there is an option to refactor a project to use AndroidX libraries as opposed to the support libraries. It's literally a one-click-fix to convert existing projects to use AndroidX. This isn't required but highly recommended since it makes the migration to AndroidX very simple.


Updating Android Studio is very simple.


  1. In Android Studio go to File > Settings

2. Navigate here and click on Check Now to check for updates.

No alt text provided for this image

3. Let Android Studio do its thing and you are done


Step 2. Migrating to AndroidX

Now that you have Android Studio version 3.+, migrating to AndroidX is very simple.

  1. In Android Studio go to Refactor > Migrate to AndroidX
No alt text provided for this image

2. Android Studio will ask you if you want to backup your project as a zip file. I recommend saying yes. You can never be too careful.

3. Let Android Studio do its thing and you are done

Note:

If you have any Maven dependencies that have not been migrated to the AndroidX namespace, the Android Studio build system also migrates those dependencies for you when you set the following two flags to true in your gradle.properties file:

android.useAndroidX=true

android.enableJetifier=true

No alt text provided for this image

Now in your build.gradle app file you'll be able to add dependencies like these ones:

No alt text provided for this image

Final Thoughts

Personally, I really like the direction they're going with this new naming convention (but who wouldn't?!). In addition to that, the new Material.io website looks really awesome. The way they've laid it out is very intuitive and it's full of great examples.


It really seems like the Android team is heading in a good direction. They're constantly improving their documentation and helping developers conveniently adhere to Android's design guidelines.



Heba EL-Madhoun

Computer Engineer | iOS Application Developer | Swift Specialist | API Integration Expert | Debugging & Problem-Solving Enthusiast ??????

3 年

Well done wejdan????

Elmehdi MOTAQI

Android engineer | Jetpack, compose, Kotlin Coroutines

3 年

Great content

要查看或添加评论,请登录

社区洞察