What is AndroidX?

updated Dec. 7, 2018
Card image cap

Table of Contents:




Introduction


AndroidX represents a new approach to how Google is organizing their 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 in 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, MaterialDesign.io. MaterialDesign.io is technically the 'new' documentation for the com.google.android.material library.

On MaterialDesign.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 MaterialDesign.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 to 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 to 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's some examples:
com.android.support:support-compat:28.0.0-alpha1
com.android.support:recyclerview-v7:28.0.0-alpha1


Quoting the official Android blog:
"These updates will continue the 28.0.0 versioning scheme that began with 28.0.0-alpha1 in March 2018, and they will continue to be source-compatible with existing projects that depend on the android.support package."


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.

  3. Let Android Studio do its thing and your 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


  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 your 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




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




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 MaterialDesign.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.


Staying in the Loop


If you want to stay in the loop and get an email when I write new blog posts, Follow me on Instagram or join the CodingWithMitch community on my website. It only takes about 30 seconds to register.



Create an Account

Have an account? Log In

CodingWithMitch Members

Unlimited access to all courses and videos

Step by step guides to build real projects

Video downloads for offline viewing

Members can vote on what kind of content they want to see

Access to a private chat with other communnity members & Mitch

A chance to win 1 hour of free consulting every month

Become a Member

CodingWithMitch Members

Unlimited access to all courses and videos

Step by step guides to build real projects

Video downloads for offline viewing

Members can vote on what kind of content they want to see

Access to a private chat with other communnity members & Mitch

A chance to win 1 hour of free consulting every month

Become a Member

Comments