What is AndroidX?

后端 未结 10 1043
死守一世寂寞
死守一世寂寞 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:17

    It is the same as AppCompat versions of support but it has less mess of v4 and v7 versions so it is much help from Using the different components of android XML elements.

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

    AndroidX is the open-source project that the Android team uses to develop, test, package, version and release libraries within Jetpack.

    AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS and provides backward-compatibility across Android releases. AndroidX fully replaces the Support Library by providing feature parity and new libraries.

    AndroidX includes the following features:

    • All packages in AndroidX live in a consistent namespace starting with the string androidx. The Support Library packages have been mapped into the corresponding androidx.* packages. For a full mapping of all the old classes and build artifacts to the new ones, see the Package Refactoring page.

    • Unlike the Support Library, AndroidX packages are separately maintained and updated. The androidx packages use strict Semantic Versioning starting with version 1.0.0. You can update AndroidX libraries in your project independently.

    • All new Support Library development will occur in the AndroidX library. This includes maintenance of the original Support Library artifacts and introduction of new Jetpack components.

    Using AndroidX

    See Migrating to AndroidX to learn how to migrate an existing project.

    If you want to use AndroidX in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the following Android Gradle plugin flags to true in your gradle.properties file.

    • android.useAndroidX: When set to true, the Android plugin uses the appropriate AndroidX library instead of a Support Library. The flag is false by default if it is not specified.

    • android.enableJetifier: When set to true, the Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. The flag is false by default if it is not specified.

    For Artifact mappings see this

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

    AndroidX is the open-source project that the Android team uses to develop, test, package, version and release libraries within Jetpack.

    After hours of struggling, I solved it by including the following within app/build.gradle:

    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    

    Put these flags in your gradle.properties

    android.enableJetifier=true
    android.useAndroidX=true
    
    Changes in gradle:
    
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.1.0-alpha04'
    

    When migrating on Android studio, the app/gradle file is automatically updated with the correction library impleemntations from the standard library

    Refer to: https://developer.android.com/jetpack/androidx/migrate

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

    Android provides a couple of different library sets. One is called the Android support Library, and the other is called AndroidX. Selecting "Use android.* artifacts" indicates that we want to use AndroidX.

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

    Just some bits addition from my side to all available answers

    Need of AndroidX

    1. As said in amazing answer by @KhemRaj,

    With the current naming convention, it 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.

    1. Other than this,

      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!. So now with AndroidX, there is no dependence on the API level.

    Another important change is that the AndroidX artifacts will update independently, so you’ll be able to update individual AndroidX libraries in your project, rather than having to change every dependency at once. Those frustrating “All com.android.support libraries must use the exact same version specification” messages should become a thing of the past!

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

    Based on the documentation:

    androidx is 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.

    The re-designed package structure is to encourage smaller and more focused libraries. You find details regarding the artifact mappings here.

    There are support libraries (containing component and packages for backward compatibility) named "v7" when the minimal SDK level supported is 14, the new naming makes it clear to understand the division between APIs bundled with platform and the libraries for app developers which are used on different versions of Android. You can refer to official announcement for more details.

    0 讨论(0)
提交回复
热议问题