我正在阅读关于Android的一个房间库。我看到他们把android包改成了androidx。我不明白。有人能解释一下吗?

implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

甚至这也是可用的android包。

implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"

为什么需要在androidx而不是android中打包新的支持库? 现有项目中的用例和影响因素。


当前回答

Android提供了几个不同的库集。一个叫Android支持库,另一个叫AndroidX。选择“使用android。”* artifacts”表示我们想要使用AndroidX。

其他回答

AndroidX是一个开源项目,Android团队使用它在Jetpack中开发、测试、打包、版本和发布库。

AndroidX是对原来的Android支持库的一个重大改进。像支持库一样,AndroidX与Android操作系统分开发布,并提供跨Android版本的向后兼容性。AndroidX通过提供特性校验和新库完全取代了支持库。

AndroidX包含以下特性:

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.

使用AndroidX

参见迁移到AndroidX了解如何迁移现有项目。

如果你想在一个新项目中使用AndroidX,你需要将编译SDK设置为Android 9.0 (API级别28)或更高,并在你的Gradle中将以下两个Android Gradle插件标志设置为true。属性文件。

android。useAndroidX:当设置为true时,Android插件使用适当的AndroidX库而不是支持库。国旗 如果未指定,则默认为false。 android。enableJetifier:当设置为true时,Android插件会自动迁移现有的第三方库,通过重写它们的二进制文件来使用AndroidX。缺省情况下,该标志为false 未指定。

对于工件映射,请参见此

Androidx将在28.0.0之后取代支持库。您应该迁移您的项目来使用它。androidx使用语义版本控制。使用AndroidX不会被库名和包名中显示的版本所混淆。生活变得更容易

[AndroidX和支持兼容性]

Android提供了几个不同的库集。一个叫Android支持库,另一个叫AndroidX。选择“使用android。”* artifacts”表示我们想要使用AndroidX。

它与AppCompat版本的支持相同,但它的v4和v7版本的混乱较少,因此使用android XML元素的不同组件有很大帮助。

我是从这个Android开发峰会的视频中了解AndroidX的。总结是-

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 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. Other Good libraries have migrated to AndroidX: Google play services, Firebase, Mockito 2, etc are migrated to AndroidX. New libraries will be published using AndroidX artifact: All the libraries will be in the AndroidX namespace like Android Jetpack