简体   繁体   English

如何在 AndroidX 上使用库?

[英]How to use the library on AndroidX?

I have written a library that supports AndroidX .我写了一个支持AndroidX的库。 How can I use this library with migration if I don't want to migrate my project to AndroidX yet?如果我不想将我的项目迁移到 AndroidX,我该如何使用这个库进行迁移?

Many popular libraries that have supported AndroidX say something like "If you wish to use this library now, migrate to AndroidX or use old versions".许多支持 AndroidX 的流行库都说“如果你现在想使用这个库,迁移到 AndroidX 或使用旧版本”。 So I don't think you can use an AndroidX library with an non-AndroidX project.所以我认为你不能在非 AndroidX 项目中使用 AndroidX 库。

Support libraries and AndroidX have different package name space.支持库和 AndroidX 有不同的包命名空间。 In the future, new changes in the AndroidX libraries won't be available in the support libraries.将来,支持库中将不再提供 AndroidX 库中的新更改。

Migrate the project to AndroidX or downgrade the library to support library.将项目迁移到 AndroidX 或将库降级以支持库。

Update更新

As mlyko's comment mentioned, jetifier has a reverse mode:正如 mlyko 的评论所提到的,jetifier 有一个反向模式:

https://developer.android.com/studio/command-line/jetifier#reverse_mode https://developer.android.com/studio/command-line/jetifier#reverse_mode

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 的库,但还需要分发使用支持库的版本。

I haven't tried it but it seems promising.我还没有尝试过,但看起来很有希望。

You could try the jetifier-standalone in reverse mode, to provide build with support libraries.您可以在反向模式下尝试jetifier-standalone ,以提供带有支持库的构建。 Therefore you'd have 2 releases of the library - androidx and support lib.因此,您将拥有 2 个版本的库 - androidx 和支持库。

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

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