简体   繁体   English

Android X 向后兼容性

[英]Android X backwards compatibility

I have Android App that uses support library versions 27.1.2.我有使用支持库版本 27.1.2 的 Android 应用程序。 I want to consume a library written using Android X (api 28).我想使用使用 Android X (api 28) 编写的库。

There are few issues with name spacing of the library versions.库版本的名称间距几乎没有问题。

Example ...例子 ...

The library has a Dialog that I want to use with the api该库有一个我想与 api 一起使用的对话框

Dialog.show(androidx.fragment.app.FragmentActivity activity);

However all my activities are using但是我所有的活动都在使用

android.support.v4.app.FragmentActivity

and the compiler does not like this.编译器不喜欢这个。

Currently it is not an option to upgrade my project to latest version, so please no upgrade answers, unless this is the only solution.目前无法将我的项目升级到最新版本,因此请不要升级答案,除非这是唯一的解决方案。

Is there a way to resolve this incompatibility issue?有没有办法解决这个不兼容的问题?

Thanks in advance.提前致谢。

This is not possible.这不可能。 To use any library that depends on AndroidX, your project must migrate your whole project to AndroidX .要使用任何依赖于 AndroidX 的库,您的项目必须将整个项目迁移到 AndroidX

Note that the reverse is supported - you can use libraries built with Support Library in projects that use AndroidX (that's the purpose of the android.enableJetifier=true flag).请注意,反向支持-您可以使用在使用AndroidX(这是目的项目支持库建库android.enableJetifier=true标志)。

AndroidX [About] AndroidX [关于]

  • Consumer support -> Producer androidX - not compatible .消费者support -> 生产者androidX -不兼容

You should migrate your consumer to use AndroidX.您应该迁移您的使用者以使用 AndroidX。 Android Studio menu -> Refactor -> Migrate to AndroidX...

  • Consumer androidX -> Producer support - compatible .消费者androidX -> 生产者support -兼容

Consumer's gradle.properties in addition to use androidX should enable Jetifier [About] which converts support to androidX消费者的gradle.properties除了使用androidX应该启用Jetifier [About] ,它将support转换为androidX

android.useAndroidX=true
android.enableJetifier=true

[Mix AndroidX and support in a multi-module project] [在多模块项目中混合 AndroidX 和支持]

There is a way有一种方法

Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. Jetifier 工具将依赖于支持库的库迁移到依赖等效的 AndroidX 包。 But when you put -r flag, it makes him to the exactly reverse process.但是当你放置-r标志时,它会让他进入完全相反的过程。

From developer.android.com来自developer.android.com

If you pass the -r flag, the utility runs in reverse mode.如果传递 -r 标志,该实用程序将以反向模式运行。 In this mode, the utility converts AndroidX APIs to the support library equivalents, instead of the other way around.在这种模式下,该实用程序会将 AndroidX API 转换为支持库等效项,而不是相反。 Reverse mode is useful, for example, if you are developing libraries that use AndroidX APIs, but also need to distribute versions that use the support library.反向模式很有用,例如,如果您正在开发使用 AndroidX API 的库,但还需要分发使用支持库的版本。

Anyway, I will suggest to use it only in a very critical needs.无论如何,我会建议仅在非常关键的需求中使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM