What Is Androidx

What is AndroidX?

AndroidX - Android Extension Library

From AndroidX documentation

We are rolling out a new package structure to make it clearer which
packages are bundled with the Android operating system, and which are
packaged with your app's APK. Going forward, the android.* package
hierarchy will be reserved for Android packages that ship with the
operating system. Other packages will be issued in the new androidx.*
package hierarchy as part of the AndroidX library.

Need of AndroidX

AndroidX is a redesigned library to make package names more clear. So from now on android hierarchy will be for only android default classes, which comes with android operating system and other library/dependencies will be part of androidx (makes more sense). So from now on all the new development will be updated in androidx.

com.android.support.** : androidx.

com.android.support:appcompat-v7 : androidx.appcompat:appcompat
com.android.support:recyclerview-v7 : androidx.recyclerview:recyclerview
com.android.support:design : com.google.android.material:material

Complete Artifact mappings for AndroidX packages

AndroidX uses Semantic-version

Previously, support library used the SDK version but AndroidX uses the Semantic-version. It’s going to re-version from 28.0.0 → 1.0.0.

How to migrate current project

In Android Studio 3.2 (September 2018), there is a direct option to migrate existing project to AndroidX. This refactor all packages automatically.

Before you migrate, it is strongly recommended to backup your project.

Existing project

  • Android Studio > Refactor Menu > Migrate to AndroidX...
  • It will analyze and will open Refractor window in bottom. Accept changes to be done.

image

New project

Put these flags in your gradle.properties

android.enableJetifier=true
android.useAndroidX=true

Check @Library mappings for equal AndroidX package.

Check @Official page of Migrate to AndroidX

What is Jetifier?

Bugs of migrating

  • If you build app, and find some errors after migrating, then you need to fix those minor errors. You will not get stuck there, because that can be easily fixed.
  • 3rd party libraries are not converted to AndroidX in directory, but they get converted at run time by Jetifier, so don't worry about compile time errors, your app will run perfectly.

Support 28.0.0 is last release?

From Android Support Revision 28.0.0

This will be the last feature release under the android.support
packaging
, and developers are encouraged to migrate to AndroidX 1.0.0

So go with AndroidX, because Android will update only androidx package from now.

Further Reading

https://developer.android.com/topic/libraries/support-library/androidx-overview

https://android-developers.googleblog.com/2018/05/hello-world-androidx.html

AndroidX and Android Jetpack

As per the AndroidX FAQ doc:

How are androidx and AndroidX related to Jetpack?

They are all the same thing! In a sentence, androidx is the packaging and AndroidX is the development workflow for all components in Jetpack. Jetpack is the external branding for libraries within androidx.

In more detail, Jetpack is the external branding for the set of components, tools, and guidance that improve the developer experience on Android. AndroidX is the open-source development project that defines the workflow, versioning, and release policies for ALL libraries included in Jetpack. All libraries within the androidx Java package follow a consistent set of API design guidelines, conform to SemVer and alpha/beta revision cycles, and use the Android issue tracker for bugs and feature requests.

What is the difference between Android and Androidx Packages in Android Studio?

Android has been building up APIs that are backward compatable and has a lot of Android Support libraries that exist in developer APIs. To clean up this mess,Android introduced androidx libraries. AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS and provides backwards-compatibility across Android releases. AndroidX fully replaces the Support Library by providing feature parity and new libraries
You can read about androidx here https://developer.android.com/jetpack/androidx

What is the use of androidx.legacy:legacy-support-v4: dependency

androidx.legacy:legacy-support-v4 is Androidx artifacts of com.android.support:support-v4

com.android.support:support-v13 -> androidx.legacy:legacy-support-v13
com.android.support:support-v4 -> androidx.legacy:legacy-support-v4

You can find info about the library mapping here

The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs. Compatible on devices running API 14 or later.

Uses for the Support Libraries

There are a few distinct uses for the support libraries. Backward compatibility classes for earlier versions of the platform is just one of them.

  • Backward Compatibility for newer APIs - A large amount of the support libraries provide backward compatibility for newer framework classes and methods. For example, the Fragment support class provides support for fragments on devices running versions earlier than Android 3.0 (API level 11).
  • Convenience and Helper Classes - The support libraries provides a number of helper classes, particularly for user interface development. For example, the RecyclerView class provides a user interface widget for displaying and managing very long lists, useable on versions of Android from API level 7 and up.
  • Debugging and Utilities - There are a number of features that provide utility beyond code you incorporate into your app, including the support-annotations library for improved code lint checks on method inputs and Multidex support for configuring and distributing apps with over 65,536 methods.

See official documents here support-library

Difference between androidx and com.android.support

All the support libraries are dropping the v4 v7 v12 v13 etc tags and everything is refactored into the androidx packages.

They are essentially the same but for future reference androidx will be the library that we should use in our apps.

Android studio 3.2 canary that comes out this week (week of May 14, 2018) should have the tool that allows automatic refactoring to the androidx packages. There was an announcement about this at google i/o 2018.

What exactly is Android Jetpack?

On its official site, it says:

Android Jetpack is a set of libraries, tools and architectural guidance to help make it quick and easy to build great Android apps. It provides common infrastructure code so you can focus on what makes your app unique

Technically, it is the support library, android-ktx and the Android Architecture Components re-branded as a single modular "entity".

This is why all non-Android extension libraries like support, etc. are re-packaged to androidx.**.

Quote from Alan Viverette (from Android Framework Team):

Jetpack is a larger-scoped effort to improve developer experience, but AndroidX forms the technical foundation. From a technical perspective, it's still the same libraries you'd have seen under Support Library and Architecture Components.

As best practices change, you may also see libraries in the androidx.* package that are not included in Jetpack.

See https://developer.android.com/topic/libraries/support-library/refactor for more info.



Related Topics



Leave a reply



Submit