Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android X backwards compatibility

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.

like image 248
fergdev Avatar asked Mar 14 '19 22:03

fergdev


People also ask

What is the Android X?

AndroidX is a major improvement to the original Android Support Library, which is no longer maintained. androidx packages fully replace the Support Library by providing feature parity and new libraries.

Should I migrate to Android X?

So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX. Better package management. With AndroidX, you get standardized and independent versioning, as well as better standardized naming and more frequent releases.

How do I enable Android X?

Migrate an existing project using Android Studio With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar. The refactor command makes use of two flags. By default, both of them are set to true in your gradle.

What is Android X migration?

AndroidX is the open-source project that is introduced along with Android Jetpack. Basically, it is a major improvement to the original Android Support Library. Like the Support Library, AndroidX also ships separately from the Android OS and provides backwards-compatibility across Android releases.


Video Answer


2 Answers

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).

like image 89
ianhanniballake Avatar answered Nov 09 '22 08:11

ianhanniballake


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]

like image 32
yoAlex5 Avatar answered Nov 09 '22 07:11

yoAlex5