3

I am trying to add a new module to my project to use as a library. But the issue is the new module developed using android x components. Is it possible to use the new module with my current project without migrating to android x?.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Arun P M
  • 352
  • 1
  • 15

1 Answers1

3

Technically not possible.

The simple reason is that Gradle cannot build an android app having both android support libraries and androidx libraries without any conversion, this would cause a merge conflict on classes.

What happens behind the scene during a build

Library A

implementation 'com.android.support:appcompat-v7:28.0.0'

Library B

implementation 'com.android.support:appcompat-v7:26.0.0'

Because the classes inside both packages are the similar: Gradle merges them to form one.

Now imagine the scenario

What happens behind the scene during a build

Library A

implementation 'com.android.support:appcompat-v7:28.0.0'

Library B

implementation 'androidx.appcompat:appcompat:1.0.0'

Now gradle becomes confuse because they're both appcompat libraries but their classes differs, hence they cannot be merged so it throws an error.

Nevertheless users whose project are on androidx can still use android support referenced libraries with the help of Jetpack Jetifier tool which would convert the support references into corresponding androidx libraries during build.

Unless you want to develop you own tool naming it UnJetifier then the option for building both android support referenced libraries and androidx libs in a support project would be possible. Best advice would be to migrate your app to androidx cause you are missing out on lots of features.

Giddy Naya
  • 4,237
  • 2
  • 17
  • 30
  • Thanks, Giddy Naya for the detailed explanation. – Arun P M Jul 30 '19 at 12:39
  • In my rare case, I'm able to run both *Android Support Library* & *AndroidX* - *Android Support Library* sub-module runs well - *AndroidX* sub-module runs well. But, the above cases are not dependent each others. It just runs as individual library. – mochadwi Nov 12 '19 at 09:16
  • In my rare case, I'm able to run both *Android Support Library* & *AndroidX* - *Android Support Library* sub-module runs well - *AndroidX* sub-module runs well. But, the above cases are not dependent each others. It just runs as individual library. – mochadwi Nov 12 '19 at 09:16