7

I have Android App that uses support library versions 27.1.2. I want to consume a library written using 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

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.

fergdev
  • 963
  • 1
  • 13
  • 27

3 Answers3

11

This is not possible. To use any library that depends on AndroidX, your project must migrate your whole project to 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).

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
2

AndroidX[About]

  • Consumer support -> Producer androidX - not compatible.

You should migrate your consumer to use AndroidX. Android Studio menu -> Refactor -> Migrate to AndroidX...

  • Consumer androidX -> Producer support - compatible.

Consumer's gradle.properties in addition to use androidX should enable Jetifier[About] which converts support to androidX

android.useAndroidX=true
android.enableJetifier=true

[Mix AndroidX and support in a multi-module project]

yoAlex5
  • 29,217
  • 8
  • 193
  • 205
0

There is a way

Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. But when you put -r flag, it makes him to the exactly reverse process.

From developer.android.com

If you pass the -r flag, the utility runs in reverse mode. In this mode, the utility converts AndroidX APIs to the support library equivalents, instead of the other way around. 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.

Anyway, I will suggest to use it only in a very critical needs.

Hayk Nahapetyan
  • 4,452
  • 8
  • 42
  • 61