What is AndroidX?

后端 未结 10 1026
死守一世寂寞
死守一世寂寞 2020-11-22 03:38

I am reading about a room library of Android. I see they changed package android to androidx. I did not understand that. Can someone explain, pleas

相关标签:
10条回答
  • 2020-11-22 04:38

    This article Android Jetpack: What do the recent announcements mean for Android’s Support Library? explains it well

    Today, many consider the Support Library an essential part of Android app development, to the point where it’s used by 99 percent of apps in the Google Play store. However, as the Support Library has grown, inconsistencies have crept in surrounding the library’s naming convention.

    Initially, the name of each package indicated the minimum API level supported by that package, for example, support-v4. However, version 26.0.0 of the Support Library increased the minimum API to 14, so today many of the package names have nothing to do with the minimum supported API level. When support-v4 and the support-v7 packages both have a minimum API of 14, it’s easy to see why people get confused!

    To clear up this confusion, Google is currently refactoring the Support Library into a new Android extension library (AndroidX) package structure. AndroidX will feature simplified package names, as well as Maven groupIds and artifactIds that better reflect each package’s content and its supported API levels.

    With the current naming convention, it also isn’t clear which packages are bundled with the Android operating system, and which are packaged with your application’s APK (Android Package Kit). To clear up this confusion, all the unbundled libraries will be moved to AndroidX’s androidx.* namespace, while the android.* package hierarchy will be reserved for packages that ship with the Android operating system.

    0 讨论(0)
  • 2020-11-22 04:39

    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.

    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

    0 讨论(0)
  • 2020-11-22 04:40

    androidx will replace support library after 28.0.0. You should migrate your project to use it. androidx uses Semantic Versioning. Using AndroidX will not be confused by version that is presented in library name and package name. Life becomes easier

    [AndroidX and support compatibility]

    0 讨论(0)
  • 2020-11-22 04:42

    I got to know about AndroidX from this Android Dev Summit video. The summarization is -

    1. No more support library: The android support library will be never maintained by Google under the support library namespace. So if you want to find fixes of a bug in support library you must have to migrate your project in AndroidX
    2. Better package management: For standardized and independent versioning.Because previous support library versioning was too confusing. It will release you the pain of “All com.android.support libraries must use the exact same version specification” message.
    3. Other God libraries have migrated to AndroidX: Google play services, Firebase, Mockito 2, etc are migrated to AndroidX.
    4. New libraries will be published using AndroidX artifact: All the libraries will be in the AndroidX namespace like Android Jetpack
    0 讨论(0)
提交回复
热议问题